Spring 集成不转换 ByteMessage

Spring integration not transforming ByteMessage

我有一个 JMS 侦听器,它正在从另一个应用程序接收 ByteMessage。当前应用程序正在使用 Spring JMS。我在这里尝试介绍 spring 集成。所以我添加了以下示例代码来监听消息。

@Configuration
public class JmsConfiguration {

@Bean
public IntegrationFlow integrationFlow(ConnectionFactory connectionFactory) {

    return IntegrationFlows
            .from(Jms.messageDrivenChannelAdapter(connectionFactory)
                    .destination("fooQueue"))
                    .transform("hello "::concat)
                    .get();
}

然后我得到如下 class 转换异常:

java.lang.ClassCastException: [B cannot be cast to java.lang.String

我收到一个 ByteMessage,但我没有找到一个很好的例子来说明如何提取带有字节数组负载的 ByteMessage。我是 spring 集成领域的新手。

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