我在将消息发送到spring-cloud-stream spring-boot应用程序时遇到了问题 . 我使用rabbitMq作为消息引擎 . 消息生成器是一个非spring-boot应用程序,它使用Spring RestTemplate发送消息 .
队列名称:“audit.logging.rest”
消费者应用程序设置为侦听该队列 . 这个应用程序是spring-boot应用程序(spring-cloud-stream) .
以下是消费者代码
application.yml
cloud:
stream:
bindings:
restChannel:
binder: rabbit
destination: audit.logging
group: rest
AuditServiceApplication.java
@SpringBootApplication
public class AuditServiceApplication {
@Bean
public ByteArrayMessageConverter byteArrayMessageConverter() {
return new ByteArrayMessageConverter();
}
@Input
@StreamListener(AuditChannelProperties.REST_CHANNEL)
public void receive(AuditTestLogger logger) {
...
}
AuditTestLogger.java
public class AuditTestLogger {
private String applicationName;
public String getApplicationName() {
return applicationName;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
}
以下是以JSON格式从 生产环境 者App发送的请求 .
{"applicationName" : "AppOne" }
发现了几个问题: Issue1: 我注意到以下方法仅在方法Parameter被提及为Object时被触发,因为spring-cloud-stream无法将消息解析为Java POJO对象 .
@Input
@StreamListener(AuditChannelProperties.REST_CHANNEL)
public void receive(AuditTestLogger logger) {
Issue2:
当我改变接收对象的方法时 . 我看到该对象的类型为RMQTextMessage,无法解析 . 但是我在其中看到了针对text属性的实际发布消息 .
我写了一个ByteArrayMessageConverter甚至没有帮助 .
有没有办法告诉spring cloud stream使用MessageConverter从RMQTextMessage中提取消息并从中获取实际消息 .
提前致谢..
2 回答
RMQTextMessage
?看起来它是rabbitmq-jms-client
的一部分 .对于RabbitMQ Binder,您应该只依赖Spring AMQP .
现在让我们弄清楚你的 生产环境 者应用程序正在做什么 .
因为
@StreamListener
方法的值为@StreamListener
,它告诉我发送方确实使用rabbitmq-jms-client
进行生成,因此队列中的真实AMQP消息将RMQTextMessage
作为真实payload
的包装 .为什么不在那里使用Spring AMQP呢?
这是一个迟到的回复,但我有确切的问题,并通过发送和接收应用程序/ json格式的消息解决它 . 在spring cloud stream config中使用它 .