How to configure MassTransit to retry context.Publish() in case of failure?

青春壹個敷衍的年華 提交于 2020-07-11 06:47:28

问题


How to configure MassTransit to retry context.Publish() before failing, for example when RabbitMQ server is temporary unavailable?


回答1:


The problem with retry in this context is that the only real reason a Publish call would fail is if the broker connection was lost (for any reason: network, etc.).

In that case, the connection which was used to receive the message is also lost, meaning that another node connected to the broker may have already picked up the message. So a retry in this case would be bad, since it would reconnect to the broker and send, but then the message could not be acknowledged (since it was likely picked up on another thread/worker).

The usual course of action here is to let it fail, and when the receive endpoint reconnects, the message will be redelivered to a consumer which will then call Publish and reach the desired outcome.

You should make sure that your consumer can handle this (search for idempotent) properly to avoid a failure causing a break in your business logic.



来源:https://stackoverflow.com/questions/44412862/how-to-configure-masstransit-to-retry-context-publish-in-case-of-failure

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