问题
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