gpt4 book ai didi

java - 'sequenceNumber' header 值必须是整数。但它很长

转载 作者:行者123 更新时间:2023-11-30 10:25:03 25 4
gpt4 key购买 nike

我正在使用 RabbitMQ 3.6.10 UI 发布一条消息,该消息由使用 Spring Integration AMQP 4.3.11 的 Java 应用程序接收。该消息是对使用 Splitter 创建的较早消息的回复,因此它具有 sequenceNumbersequenceSize header 。我将这些 header 复制到回复中,并将它们设置为 RabbitMQ UI 中的 Number 类型。但是,在 Java 方面,我遇到了一个异常(exception):

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 端的 sequenceNumbersequenceSize header 的类型是 Long,而不是 Integer。然而,没有选项可以在 RabbitMQ UI 中实现这种差异。消息将由非 Java 应用程序发送,那么如何确保 header 被 Spring Integration 识别为 Integer?

当我使用 Java 客户端发布回复并将 header 值设置为 Integer 时,消费者会接受它们。所以这可能是 RabbitMQ UI 的限制,没有足够具体的 header 类型(例如 32 位与 64 位数字)或 Java 客户端对预期值类型过于严格。任何人都可以确认其中之一吗?

最佳答案

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 - 我们可能应该更宽松一些,尤其是当值为 <<Integer.MAX_VALUE 时。

关于java - 'sequenceNumber' header 值必须是整数。但它很长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46424117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com