-
Notifications
You must be signed in to change notification settings - Fork 606
Event handlers for Channel.ChannelShutdownAsync and Consumer.ShutdownAsync are all called on the last registration? #1837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
@viblo-majority,I am not sure I understand the problem. Your code is wrong btw, you are using the variable using RabbitMQ.Client;
using RabbitMQ.Client.Events;
Console.WriteLine("Queue Receive Test");
var connectionFactor = new ConnectionFactory
{
HostName = "localhost",
Port = 5672,
VirtualHost = "/",
};
var connection = await connectionFactor.CreateConnectionAsync();
connection.ConnectionShutdownAsync += (sender, e) =>
{
Console.WriteLine($"Connection shutdown");
return Task.CompletedTask;
};
int count = 0;
for (var i = 0; i < 2; i++)
{
var channel = await connection.CreateChannelAsync();
// Console.WriteLine($"Channel {i} created: {channel.ChannelNumber} {channel.CurrentQueue} {channel}");
channel.ChannelShutdownAsync += (sender, e) =>
{
var c = (IChannel)sender;
Console.WriteLine(
$"[ChannelShutdownAsync] Channel {c.ChannelNumber} shutdown: {c.ChannelNumber} {c.CurrentQueue} {c.ChannelNumber == channel.ChannelNumber}");
return Task.CompletedTask;
};
var queueName = $"queue-{i}";
await channel.QueueDeclareAsync(queueName, true, false, false);
var consumer = new AsyncEventingBasicConsumer(channel);
consumer.ShutdownAsync += (sender, e) =>
{
var c = (AsyncEventingBasicConsumer)sender;
Console.WriteLine(
$"[ShutdownAsync] Consumer {c.Channel.ChannelNumber} shutdown: {c.Channel.CurrentQueue} {c == consumer}");
return Task.CompletedTask;
};
consumer.ReceivedAsync += async (model, ea) =>
{
Console.WriteLine($"Received from {queueName}");
await channel.BasicAckAsync(ea.DeliveryTag, false);
};
await channel.BasicConsumeAsync(queueName, false, consumer);
Console.WriteLine($"Consumer with channel id:{channel.ChannelNumber} started on {queueName}");
}
// Thread.Sleep(500);
await connection.CloseAsync();
Console.WriteLine("Setup complete. Waiting...");
Console.ReadLine(); result:
|
I think we can close this. cc @lukebakken @michaelklishin |
@viblo-majority I am going to close the issue. Feel free to reopen in case of problems |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
If I create two channels with a consumer each, register a ChannelShutdownAsync callback and then break the connection I will get two callbacks, but both of them will go to the last callback registered.
Im not sure if this is a bug or if it is intendend.. but at least I think it is a bit confusing.
In my example below I get this output:
I thought that each callback registered would be called once, and not the same callback twice:
Reproduction steps
Run the below code (with adjusted rabbit connection details), and when its running then break the connection to rabbit, for example by turning it off if run locally.
Expected behavior
I expected a call to each callback I register, not double callbacks to the last callback registered.
Additional context
No response
The text was updated successfully, but these errors were encountered: