IBus.Publish not respecting CancellationToken
See original GitHub issueIs this a bug report?
Yes
Can you also reproduce the problem with the latest version?
Yes
Environment
- Operating system: Windows 10 x64 Build 1809
- Visual Studio version: 2019
- Dotnet version: Core 3.0
- MT version: 6.2.1
Steps to Reproduce
(Write your steps here:)
- Setup a RabbitMQ bus instance
- Create CancellationTokenSource instance that cancels after a period of time
- Call IBus.Publish
Expected Behavior
I would expect either IPublishEndpoint
to behave similar to ISendEndpoint
where if RabbitMQ is down it throws an exception immediately or the call to Publish
would hang and the task would cancel when the time span specified is reached.
Actual Behavior
The task never completes and only shows the task as being cancelled after RabbitMQ service is back up.
Reproducible Demo
static async Task Main(string[] args) {
var cts = new CancellationTokenSource();
var bus = Bus.Factory.CreateUsingRabbitMq(cfg => {
cfg.Host("localhost");
cfg.ReceiveEndpoint("value-entered", e => {
e.Consumer<Program>();
});
});
try {
await bus.StartAsync();
// Stop the RabbitMQ service before publish
cts.CancelAfter(TimeSpan.FromSeconds(15));
await bus.Publish(new ValueEntered(), cts.Token);
// *NOTE* Using a send endpoint when RabbitMQ is down causes an exception to throw immediately
//var sendEndpoint = await bus.GetSendEndpoint(new Uri("rabbitmq://localhost/value-entered"));
//await sendEndpoint.Send(new ValueEntered(), cts.Token);
}
catch (TaskCanceledException e) {
Console.WriteLine($"Publish cancelled. Message: {e.Message}");
}
catch (Exception err) {
Console.WriteLine($"Error: {err.Message}");
}
finally {
await bus.StopAsync();
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
How to cancel long running task in MassTransit
I found a solution so if i use this. e.Consumer(() => { return reqConume; //this is a singleton });. and as a singleton...
Read more >Producers
Publish also supports cancellation, including timeouts. See the note above for details.
Read more >How to stop automatic candidate insertion with ibus-table?
The “cancel” key binding (default: Esc ) doesn't select the candidate, but gets rid of the entered text entirely, so that's not helpful....
Read more >Using MassTransit with RabbitMQ in ASP.NET Core
In this article, we are going to take a look at how we can use the open-source, distributed application library MassTransit in conjunction ......
Read more >RabbitMQ: AMQP Channel Best Practices - Code rant
Do not mix publishing and consuming on the same channel. If you follow the suggestion above, it implies that you have dedicated channels...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you again @phatboyg for looking at this and fixing it so quickly.
Good news! When do you think a new nuget package will be published with the fix?