spring - Spring集成不转换ByteMessage
问题描述
我有一个 JMS 侦听器,它正在从另一个应用程序接收 ByteMessage。当前应用程序正在使用 Spring JMS。我想在这里介绍弹簧集成。所以我添加了以下示例代码来监听消息。
@Configuration
public class JmsConfiguration {
@Bean
public IntegrationFlow integrationFlow(ConnectionFactory connectionFactory) {
return IntegrationFlows
.from(Jms.messageDrivenChannelAdapter(connectionFactory)
.destination("fooQueue"))
.transform("hello "::concat)
.get();
}
然后我得到如下的类转换异常:
java.lang.ClassCastException: [B cannot be cast to java.lang.String
我得到一个 ByteMessage,但我没有找到一个很好的例子来说明如何提取带有字节数组有效负载的 ByteMessage。我是春季集成世界的新手。
解决方案
.transform(Transformers.objectToString())
在您的.transform()
. BytesMessage
将产生带有byte[]
有效负载的消息,因此您需要String
在尝试连接之前将其转换为 a 。
推荐阅读
- node.js - Emoji 必须是字符串或 Emoji/ReactionEmoji 从获取自定义表情
- node.js - 指纹JS2生命周期错误
- php - 独立于会议类别单击“所有类别”时获取会议
- reactjs - ./node_modules/recompose/dist/Recompose.esm.js 中的错误找不到模块:错误:无法解析“@babel/runtime/helpers/builtin/es6/extends”
- android - Ad Consent Android App - 如何清除以便可以重试
- html - 如何在 ionic 的 ts 文件中使用来自 Api 的数据
- r - R:geom_image 被 coord_fixed 变形
- javascript - 点击时卡片翻转,仅使用关闭框关闭
- sql - 如何在没有手动硬编码的情况下在 bigquery 标准 SQL 中透视数据?
- c# - 我的素数程序中的逻辑错误