Apache camel 骆驼兔mq+;ConvertSendReceive():无法转换内容类型为[null]的传入消息
我有一个组件,它向工作者服务发送消息,等待返回结果Apache camel 骆驼兔mq+;ConvertSendReceive():无法转换内容类型为[null]的传入消息,apache-camel,rabbitmq,spring-amqp,Apache Camel,Rabbitmq,Spring Amqp,我有一个组件,它向工作者服务发送消息,等待返回结果 @Autowired private RabbitTemplate rabbit; [...] Object response = rabbit.convertSendAndReceive("testQ", ...); 辅助服务是通过Apache Camel rabbitmq路由实现的: from("rabbitmq://localhost/myExchange?declare=false&routingKey=testQ&q
@Autowired
private RabbitTemplate rabbit;
[...]
Object response = rabbit.convertSendAndReceive("testQ", ...);
辅助服务是通过Apache Camel rabbitmq路由实现的:
from("rabbitmq://localhost/myExchange?declare=false&routingKey=testQ&queue=testQ")
.routeId("myCamelRoute")
.process(myProcessor)
.to("log:myLog");
myProcessor处理消息并注销驼峰消息头:
__TypeId__=...
breadcrumbId=...
rabbitmq.CONTENT_ENCODING=UTF-8
rabbitmq.CONTENT_TYPE=application/json
rabbitmq.CORRELATIONID=7e390b6b-d30f-4f26-ba44-33fb887db0e8
rabbitmq.DELIVERY_TAG=4
rabbitmq.EXCHANGE_NAME=
rabbitmq.PRIORITY=0
rabbitmq.REPLY_TO=amq.rabbitmq.reply-to.g2dkABNyYWJiaXRAOWU5ZjkxNDI4ZWRiAAAJgwAAADUC.5+kPXXxaXhoYo7A4T0HSZQ==
rabbitmq.ROUTING_KEY=testQ
消息头在工作端显然包含rabbitmq.CONTENT\u TYPE=application/json,但当响应消息返回时,此信息似乎“丢失”:
o、 s.a.s.c.Jackson2JsonMessageConverter:无法转换
内容类型为[null]的传入消息
知道这里出了什么问题吗?在使用Headers字段时,我在使用RabbitMQ管理控制台时看到了相同的错误。
将“content\u type”:“application/json”作为消息属性传递很好。EDIT:实际上,chrome autocomplete似乎工作不正常。我手动键入了属性,工作也很好
我也面临同样的问题。这似乎是RabbitMQ管理控制台和Spring使用者之间的问题 基于,我重写了来自Jackson2JsonMessageConverter的fromMessage方法,并强制contentType为application/json,工作正常 我的堆栈是:
- org.springframework:4.3.6.RELEASE
- org.springframework.amqp:1.7.14.RELEASE
- com.fasterxml.jackson.core:2.11.2
import org.springframework.amqp.core.Message;
导入org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
公共类JacksonMessageConverter扩展了Jackson2JsonMessageConverter{
公共JacksonMessageConverter(){
超级();
}
@凌驾
来自消息的公共对象(消息消息){
message.getMessageProperties().setContentType(“应用程序/json”);
返回super.fromMessage(message);
}
}
如果弹簧amqp:
@Bean
public CachingConnectionFactory cachingConnectionFactory() {
final CachingConnectionFactory factory = new CachingConnectionFactory();
factory.setUsername(username);
factory.setPassword(password);
factory.setHost(host);
factory.setPort(port);
return factory;
}
@Bean
@DependsOn("cachingConnectionFactory")
public RabbitTemplate rabbitTemplate(CachingConnectionFactory cachingConnectionFactory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(cachingConnectionFactory);
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
return rabbitTemplate;
}
我不知道camel,所以我不能真正发表评论,但看起来回复消息需要一个内容类型的标题。