Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
473 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...