Question about session usage / link allocation in RabbitMQ.AMQP.Client (.NET, AMQP 1.0) #138
-
|
Hi, I’m using RabbitMQ.AMQP.Client in a banking system (ASP.NET Core, .NET 8) and I’m trying to understand how sessions are actually used by the client library. From the docs and AMQP 1.0 model I expect something like “one connection → some sessions → many links”, but in practice I’m seeing different behavior in the RabbitMQ management UI depending on startup vs reconnect. What I’m doingI have a small wrapper around the client:
How I actually use the consumersEvery queue in the system is handled by a dedicated BackgroundService (derived from a base message-processing service). Relevant piecesPublisher pool ConsumerManager So effectively:
What I see in RabbitMQ UIOn first startup of the API:
Then, if I:
So from the outside it looks like: initial startup: one connection → many sessions → links This might be me misreading the UI, but it’s consistent. Questions1. How does the library decide when to create a new session?
2. Why do I sometimes see “one session per link” and later “one session for all links”? Is this expected behavior with recovery + negotiation?
3. Max sessions per connection
4. Recommended usage pattern For long-lived services with many consumers and publishers on a few connections, what is the intended pattern?
If explicit control of session count is recommended, how should it be done with the current API? I want to make sure I’m not unintentionally creating too many sessions and that I’m interpreting the management UI correctly. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
Thank you, @allenyo, will check it soon. |
Beta Was this translation helpful? Give feedback.
-
|
@allenyo I tried our HAClient example with these changes, just to add more producers and consumers: diff --git a/docs/Examples/HAClient/Program.cs b/docs/Examples/HAClient/Program.cs
index bc0c3e9..ce4ce75 100644
--- a/docs/Examples/HAClient/Program.cs
+++ b/docs/Examples/HAClient/Program.cs
@@ -56,6 +56,9 @@
await queueSpec.DeclareAsync();
IPublisher publisher = await connection.PublisherBuilder().Queue(queueName).BuildAsync();
+IPublisher publisher1 = await connection.PublisherBuilder().Queue(queueName).BuildAsync();
+IPublisher publisher2 = await connection.PublisherBuilder().Queue(queueName).BuildAsync();
+IPublisher publisher3 = await connection.PublisherBuilder().Queue(queueName).BuildAsync();
AsyncManualResetEvent pausePublishing = new(true);
publisher.ChangeState += (sender, fromState, toState, e) =>
@@ -80,6 +83,31 @@
}
).BuildAndStartAsync();
+IConsumer consumer1 = await connection.ConsumerBuilder().Queue(queueName).InitialCredits(100).MessageHandler((context, message) =>
+ {
+ Interlocked.Increment(ref messagesReceived);
+ context.Accept();
+ return Task.CompletedTask;
+ }
+).BuildAndStartAsync();
+
+
+IConsumer consumer2 = await connection.ConsumerBuilder().Queue(queueName).InitialCredits(100).MessageHandler((context, message) =>
+ {
+ Interlocked.Increment(ref messagesReceived);
+ context.Accept();
+ return Task.CompletedTask;
+ }
+).BuildAndStartAsync();
+
+IConsumer consumer4 = await connection.ConsumerBuilder().Queue(queueName).InitialCredits(100).MessageHandler((context, message) =>
+ {
+ Interlocked.Increment(ref messagesReceived);
+ context.Accept();
+ return Task.CompletedTask;
+ }
+).BuildAndStartAsync();
+
consumer.ChangeState += (sender, fromState, toState, e) =>
{
Trace.WriteLine(TraceLevel.Information, $"Consumer State Changed, from {fromState} to {toState}");That's when the client starts:
That's when I kill the connection:
That's when I restart the node:
I am unable to reproduce your situation. If you can reproduce it with the HA client, it would be great. The idea, at the moment, is to have --> one connection --> one session, --> multiple links! but we can ghange it |
Beta Was this translation helpful? Give feedback.





@allenyo can you please try #139 ?