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

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

c# - Configure rabbitMQ IConnection and IModel/IChannel

I'm not exactly sure how to configure rabbitmq's IConfiguration and IModel lifescopes in my .net core app.

According to the docs, the IConnection object should be longed lived, so I'm guessing this is a one time operation. For that I'm just creating a single instance and then re-use it (like a singleton).

My issues is with the IModel,

  1. how many should I create (what is the driven factor(s) that I have to take into account when creating this object)?
  2. again acording to the docs, it state that it should be long lived with a mention that it can be smaller then that of the IConnection instance from which it was created?
question from:https://stackoverflow.com/questions/65855089/configure-rabbitmq-iconnection-and-imodel-ichannel

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

1 Answer

0 votes
by (71.8m points)
  1. In .NET client channels are represented using the IModel interface, Therefore by using multiple IModels you are basically using multiple channels on top of the same connection. Each of the channels can have its own consumer and you can use it to process multiple messages in parallel, which would provide execution time advantages in particular scenarios.

  2. By long-lived it means since the creation of a channel is a resource-consuming process, It would be better to set it up once during the application lifetime.

AMQP 0-9-1 provides a way for connections to multiplex over a single TCP connection. That means an application can open multiple "lightweight connections" called channels on a single connection. AMQP 0-9-1 clients open one or more channels after connecting and perform protocol operations (manage topology, publish, consume) on the channels.

And by lightweight, it means each channel would use the same TCP connection and needs fewer resources in comparison with a Connection.

In conclusion, you need only one connection, and you can have multiple channels on top of it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...