简体   繁体   English

Spring cloud stream rabbit binder:向DLQ发送批处理消息时出错

[英]Spring cloud stream rabbit binder : Error sending batch messages to DLQ

I am trying to configure a spring-cloud-stream application with a rabbit binder我正在尝试使用兔子活页夹配置 spring-cloud-stream 应用程序

spring cloud stream : 3.1.4
spring cloud stream rabbit binder : 3.1.4
spring version : 2.5.5

Here under is my configuration :下面是我的配置:

spring:
  cloud:
    stream:
      rabbit:
        bindings:
          listen-in-0:
            consumer:
              queueNameGroupOnly: true
              enable-batching: true
              batch-size: 100
              receive-timeout: 500
              transacted: true
          listen-out-0:
            producer:
              queueNameGroupOnly: true
              transacted: true
              batchingEnabled: false
              enable-batching: false
      bindings:
        listen-in-0:
          destination: test.request
          group: test.request
          consumer:
            batch-mode: true
            requiredGroups: test.request
            maxAttempts: 1
        listen-out-0:
          destination: test.response
          group:  test.response
          producer:
            requiredGroups:  test.response

My java code for consumer :我的消费者 Java 代码:

@Bean
    public Function<Message<List<Request>>, List<Message<Response>>> listen() {
      ...
    }
}

When no error occurs all works fine.当没有发生错误时,一切正常。 But when i simulate an exception, i got the here under exception :但是当我模拟异常时,我得到了异常:

2021-10-27 17:08:31,997 [rs-worker] [test.request-1] WARN  o.s.a.r.l.ConditionalRejectingErrorHandler$DefaultExceptionStrategy []    - Fatal message conversion error; message rejected; it will be dropped or routed to a dead letter exchange, if so configured: (Body:'[B@7891e2d2(byte[18])' MessageProperties [headers={tenant=tenant1, request.id=75c328f6-42a9-4682-952e-46d088a5c09e}, contentType=application/octet-stream, contentLength=0, receivedDeliveryMode=PERSISTENT, priority=0, redelivered=false, receivedExchange=test.request, receivedRoutingKey=#, deliveryTag=1, consumerTag=amq.ctag-S0u7Mj4EwX13Kzj_CgzGVg, consumerQueue=test.request])
2021-10-27 17:08:31,997 [rs-worker] [test.request-1] ERROR o.s.a.r.l.SimpleMessageListenerContainer []    - Execution of Rabbit message listener failed, and the error handler threw an exception
org.springframework.amqp.AmqpRejectAndDontRequeueException: Error Handler converted exception to fatal
    at org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler.handleError(ConditionalRejectingErrorHandler.java:146)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeErrorHandler(AbstractMessageListenerContainer.java:1460)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.handleListenerException(AbstractMessageListenerContainer.java:1744)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1519)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.executeWithList(SimpleMessageListenerContainer.java:1028)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1017)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:914)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:83)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1289)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1195)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Listener threw exception
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1767)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1660)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1575)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1563)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1558)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1498)
    ... 7 common frames omitted
Caused by: org.springframework.messaging.MessageDeliveryException: failed to send Message to channel 'test.request.errors'; nested exception is java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.springframework.amqp.core.Message
    at org.springframework.integration.support.utils.IntegrationUtils.wrapInDeliveryExceptionIfNecessary(IntegrationUtils.java:167)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:339)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:272)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109)
    at org.springframework.integration.endpoint.MessageProducerSupport.sendErrorMessageIfNecessary(MessageProducerSupport.java:254)
    at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:211)
    at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter.access$1500(AmqpInboundChannelAdapter.java:69)
    at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter$BatchListener.onMessageBatch(AmqpInboundChannelAdapter.java:481)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1652)
    ... 11 common frames omitted
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.springframework.amqp.core.Message
    at org.springframework.cloud.stream.binder.rabbit.RabbitMessageChannelBinder$2.handleMessage(RabbitMessageChannelBinder.java:663)
    at org.springframework.integration.dispatcher.BroadcastingDispatcher.invokeHandler(BroadcastingDispatcher.java:222)
    at org.springframework.integration.dispatcher.BroadcastingDispatcher.dispatch(BroadcastingDispatcher.java:178)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:72)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:317)
    ... 21 common frames omitted

This error is raised when rabbit binder tries to send back messages to DLQ.当rabbit binder 尝试将消息发送回DLQ 时,会引发此错误。

Indeed, the ErrorMessage payload contains a List<Message<?>> or spring cloud stream rabbit expect a Message<List<?>> .事实上,ErrorMessage 负载包含一个List<Message<?>>或 spring cloud stream rabbit 期望一个Message<List<?>>

Is there a workaround or do i make an error in my configuration or usage of the library ?是否有解决方法,或者我是否在配置或使用库时出错?

Thanks.谢谢。

Dead letter re-publishing in the binder is not currently supported for batch listeners.批量侦听器目前不支持在活页夹中重新发布死信。 Set republishToDlq to false.republishToDlq设置为 false。

It's hard to say whether it should be supported (ie the entire batch would be sent, even if some records are processed successfully), but it should not throw a ClassCastException .很难说它是否应该被支持(即整个批次都会被发送,即使一些记录被成功处理),但它不应该抛出ClassCastException

https://github.com/spring-cloud/spring-cloud-stream-binder-rabbit/issues/348 https://github.com/spring-cloud/spring-cloud-stream-binder-rabbit/issues/348

With a batch listener, it's best to handle exceptions in the listener itself.对于批处理侦听器,最好在侦听器本身中处理异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何配置 DeadLetterPublisherRecoverer 以在 Spring Cloud Stream 批处理模式下将错误消息发送到 DLQ - How to configure DeadLetterPublisherRecoverer to send error messages to a DLQ in Spring Cloud Stream batch mode 使用Kafka向Dlq Spring云流发送消息时出错 - Error sending message to Dlq Spring cloud stream with Kafka 使用Spring Cloud Stream对DLQ Rabbit进行不正确的绑定 - Incorrect binding for DLQ Rabbit using Spring Cloud Stream Spring 云 Stream - 修改 DLQ 消息 - Spring Cloud Stream - modify DLQ messages Spring Cloud Stream Kafka活页夹无法使用密钥发布到DLQ - Spring Cloud Stream Kafka binder fails to publish to DLQ with a key Spring Cloud Stream rabbit binder 在使用 connection-prefix 属性时导致循环依赖错误 - Spring Cloud Stream rabbit binder causing circular dependency error when using connection-prefix property Spring Cloud Stream Rabbit Binder 为所有消费者共享并发 - Spring Cloud Stream Rabbit Binder shared concurrency for all consumers spring-cloud-stream兔子绑定器未分区的目的地 - spring-cloud-stream rabbit binder un-partitioned destination Spring Cloud Stream Pojo 的 Rabbit Binder 序列化问题 - Spring Cloud Stream Rabbit Binder serialization problem for Pojo Spring Cloud Stream Rabbit Binder路由密钥总是&#39;#&#39; - Spring Cloud Stream Rabbit Binder Routing Key always '#'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM