Specify Publish timeouts in mass transit

扶醉桌前 提交于 2020-12-13 04:01:21

问题


Is there a way to specify timeout value when publishing messages using the MassTransit Library. How to handle scenarios when message broker goes down. Now it seems that Publish call waits indefinitely. It would be nice to control these behavior. Should we rely on cancellation token? Timeout implementation might be better.


回答1:


You can pass a CancellationToken to Publish. If canceled, an OperationCanceledException will be thrown. If you want to use a timeout, you can create a CancellationTokenSource with a timeout.

using var source = new CancellationTokenSource(TimeSpan.FromSeconds(30));

await bus.Publish(message, source.Token);


来源:https://stackoverflow.com/questions/64562077/specify-publish-timeouts-in-mass-transit

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