Re-queue Amqp message at tail of Queue

[亡魂溺海] 提交于 2019-12-13 05:16:42

问题


I have a project setup using Spring and RabbitMQ. Currently it is possible for my application to receive an amqp message that cannot be processed until another asynchronous process has completed (legacy and totally detached, i have no control). So the result is i may have to wait on processing a message for some amount of time. The result of this is an exception in a transformer.

When the message is NACK'd back to rabbitMQ it is putting it back into the head of the queue and re-pulling it immediately. If i get unprocessable messages equal to the number of concurrent listeners my workflow locks up. It spins its wheels waiting for messages to become processable, even though there are valid processable messages waiting behind in the queue.

Is there a way to reject and amqp message and have it go back to the tail of the queue instead? From my research rabbitMQ worked this way at one time, but now i appear to get the head of the queue exclusively.

My config is rather straight forward, but for continuity here it is...

Connection factory is: org.springframework.amqp.rabbit.connection.CachingConnectionFactory RabbitMQ 3.1.1

Spring Integration: 2.2.0

<si:channel id="channel"/>
<si-amqp:inbound-channel-adapter
    queue-names="commit" channel="channel" connection-factory="amqpConnectionFactory"
    acknowledge-mode="AUTO" concurrent-consumers="${listeners}"
    channel-transacted="true"
    transaction-manager="transactionManager"/>

<si:chain input-channel="channel" output-channel="nullChannel">
    <si:transformer ref="transformer"></si:transformer>
    <si:service-activator ref="activator"/>
</si:chain>

回答1:


You are correct that RabbitMQ was changed some time ago. There is nothing in the API to change the behavior.

You can, of course, put an error-channel on the inbound adapter, followed by a transformer (expression="payload.failedMessage"), followed by an outbound adapter configured with an appropriate exchange/routing-key to requeue the message at the back of the queue.

You might want to add some additional logic in the error flow to check the exception type (payload.cause) and decide which action you want.

If the error flow itself throws an exception, the original message will be requeued at the head, as before; if it exits normally, the message will be acked.



来源:https://stackoverflow.com/questions/19235818/re-queue-amqp-message-at-tail-of-queue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!