首页 > 解决方案 > 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。我是春季集成世界的新手。

标签: springspring-bootspring-integrationspring-jmsspring-integration-dsl

解决方案


.transform(Transformers.objectToString())在您的.transform(). BytesMessage将产生带有byte[]有效负载的消息,因此您需要String在尝试连接之前将其转换为 a 。


推荐阅读