我使用RabbitMQ 3.6.10 UI发布使用Spring Integration AMQP 4.3.11的Java应用程序接收的消息。该消息是对使用Splitter创建的早期消息的回复,因此它具有sequenceSize
和Number
标头。我将这些标题复制到回复中,并将它们设置为RabbitMQ UI中的类型org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Message conversion failed
at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter$Listener.onMessage(AmqpInboundChannelAdapter.java:223)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:822)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:745)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:97)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:189)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1276)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:726)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1219)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1189)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1500(SimpleMessageListenerContainer.java:97)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1421)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: The 'sequenceNumber' header value must be an Integer.
at org.springframework.util.Assert.isTrue(Assert.java:92)
at org.springframework.integration.IntegrationMessageHeaderAccessor.verifyType(IntegrationMessageHeaderAccessor.java:143)
at org.springframework.messaging.support.MessageHeaderAccessor.setHeader(MessageHeaderAccessor.java:298)
at org.springframework.messaging.support.MessageHeaderAccessor.copyHeaders(MessageHeaderAccessor.java:389)
at org.springframework.integration.support.MessageBuilder.copyHeaders(MessageBuilder.java:177)
at org.springframework.integration.support.MessageBuilder.copyHeaders(MessageBuilder.java:47)
at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter$Listener.processMessage(AmqpInboundChannelAdapter.java:243)
at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter$Listener.onMessage(AmqpInboundChannelAdapter.java:203)
... 14 more
。但是,在Java方面,我得到了例外:
sequenceNumber
我检查了Java端的sequenceSize
和Long
标头的类型是Integer
,而不是Integer
。然而,在RabbitMQ UI中没有选择来实现这一点。消息将由非Java应用程序发送,因此如何确保Spring Integration将标头识别为Integer?
当我使用Java客户端发布回复并将标头值设置为awk
时,消费者会接受它们。因此,这可能是RabbitMQ UI的限制,没有足够具体的头类型(例如,32位与64位数)或Java客户端对期望值类型过于严格。任何人都可以确认其中一个吗?
答案 0 :(得分:1)
将MessagePostProcessor
添加到适配器的侦听器容器...
@Bean
public AmqpInboundChannelAdapter adapter(ConnectionFactory cf) {
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(listenerContainer(cf));
adapter.setOutputChannelName("someChannel");
return adapter;
}
@Bean
public AbstractMessageListenerContainer listenerContainer(ConnectionFactory cf) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
container.setQueueNames("foo");
container.setAfterReceivePostProcessors(m -> {
if (m.getMessageProperties().getHeaders()
.get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER) instanceof Long) {
Integer sequenceNumber = ((Long) m.getMessageProperties().getHeaders()
.get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)).intValue();
m.getMessageProperties().getHeaders().put(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER,
sequenceNumber);
}
return m;
});
return container;
}
请打开JIRA Issue - 我们应该更宽容,特别是如果值<&lt; Integer.MAX_VALUE
。