[英]Content type different in RabbitListener Spring AMQP using ContentTypeDelegatingMessageConverter
Actually I'm using Spring AMQP to consume XML from Rabbit.实际上,我正在使用 Spring AMQP 从 Rabbit 消耗 XML。
Here is my code for Listen the queue.这是我听队列的代码。
@RabbitListener(queues = DealerReceiverConfig.P8_QUEUE_NAME, id = Constants.P8_QUEUE_ID)
@SendTo("foo.bar")
public RequestDocument p8ContentReceiveMessage(RequestDocument request) {
System.out.println(request.getCorrelationId());
return request;
}
and my rabbit template configuration is:我的兔子模板配置是:
@Override
@Bean(name = "dealerRabbit")
public RabbitTemplate rabbitTemplateSeguros(ConnectionFactory connectionFactory) {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setMessageConverter(producerMessageConverter());
return template;
}
@Override
@Bean
public MessageConverter producerMessageConverter() {
ContentTypeDelegatingMessageConverter messageConverter = new ContentTypeDelegatingMessageConverter();
Jackson2JsonMessageConverter jsonMessageConverter = new Jackson2JsonMessageConverter();
messageConverter.addDelegate("application/json", jsonMessageConverter);
MarshallingMessageConverter marshaller = new MarshallingMessageConverter();
marshaller.setMarshaller(oxmMarshaller());
marshaller.setUnmarshaller(oxmUnMarshaller());
messageConverter.addDelegate("application/xml", marshaller);
return messageConverter;
}
@Bean
public Marshaller oxmMarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("foo.bar.model");
return marshaller;
}
@Bean
public Unmarshaller oxmUnMarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("foo.bar.model");
return marshaller;
}
The problem is when I see the returned message in the @SentTo queue configured, I get the following message.问题是当我在配置的@SentTo 队列中看到返回的消息时,我收到以下消息。
Any suggestions?有什么建议么?
Thanks for your help.谢谢你的帮助。
The template is not used to send replies from @RabbitListener
s;该模板不用于发送来自@RabbitListener
的回复; you need to add the converter to the RabbitListenerContainerFactory
( Simple...
or Direct...
, depending on which container type you are using).您需要将转换器添加到RabbitListenerContainerFactory
( Simple...
或Direct...
,具体取决于您使用的容器类型)。
EDIT编辑
It's a bug;这是一个错误; you should be able to do this...你应该能够做到这一点......
@RabbitListener(queues = "foo")
@SendTo("bar")
public Message<String> listen(String in) {
System.out.println(in);
return MessageBuilder.withPayload(in.toUpperCase())
.setHeader(MessageHeaders.CONTENT_TYPE, "application/xml")
.build();
}
But the adapter still uses a raw MessageProperties
which has application/x-java-serialized-object
as the default CT.但是适配器仍然使用原始的MessageProperties
,它具有application/x-java-serialized-object
作为默认 CT。
https://github.com/spring-projects/spring-amqp/issues/1219 https://github.com/spring-projects/spring-amqp/issues/1219
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.