[rabbitmq-discuss] Best Practices using Connection and Channels

2,878 views
Skip to first unread message

Marcus Vinitius Baffa

unread,
May 6, 2011, 10:40:48 AM5/6/11
to rabbitmq...@lists.rabbitmq.com

I am new to RabbitMq and I need to develop an application that will have something like 30 to 50 concurrent clients. Each client will send commands to my server. The server applicaton, a .NET C# application, will start a new thread to execute each command.

 

I would like to know if you consider a good practice in using AMQP Connections and Channels:

 

·         1 Connection per application or 1 Connection per Client;

·         1 Channel per Exchange/Queue and/or Thread. If the application has more than one thread each one must create a new channel using the same application/client connection.

·         Some people advise to create a Channel Pools, is it a good practice.

 

What do you think about it ???

Simone

unread,
May 9, 2011, 3:51:07 AM5/9/11
to rabbitmq...@googlegroups.com, rabbitmq...@lists.rabbitmq.com
Hi Marcus, you can find some info in the Java API guide. I am going to use the .NET API soon but I didn't have time to look into the code to tell you what pattern is good, hopefully someone else can.
BTW I can tell you what I think would be a good way to use it. If you're familiar with NHibernate you know about session factory and session. I think that in the same way I would like to design my application so that there is a single connection and each thread creates its own channel, thus making the connection the mirror of NH session factory and channel the mirror of NH session.

Simone

unread,
May 9, 2011, 8:44:09 AM5/9/11
to rabbitmq...@googlegroups.com, rabbitmq...@lists.rabbitmq.com
Hi Marcus, I was going through the faq and picked up this one:

Can you recommend the best way to work with connections and channels in my application?

In general, it is better to create a single connection and as many channels as you need (rather than many connections with a single channel each).

Marcus Vinitius Baffa

unread,
May 9, 2011, 12:42:52 PM5/9/11
to rabbitmq...@lists.rabbitmq.com

Thanks Simone,

 

That’s what I presumed to be the best solution. One connection opened when the receiver starts and for each thread that will execute a command create a channel so that the thread can send the response to the respose queue.

 

Thank you very much

Matthew Sackman

unread,
May 13, 2011, 7:40:13 AM5/13/11
to rabbitmq...@lists.rabbitmq.com
On Fri, May 06, 2011 at 11:40:48AM -0300, Marcus Vinitius Baffa wrote:
> * 1 Connection per application or 1 Connection per Client;

For the numbers you're talking about, 1 connection per application is
not going to be an issue. The IPC et al to do 1 connection per client is
likely going to be quite painful to do, so I'd not recommend that.

> * 1 Channel per Exchange/Queue and/or Thread. If the application


> has more than one thread each one must create a new channel using the
> same application/client connection.

1 Channel per Thread is definitely best practise. Certainly in the Java
client it's unwise to share channels between threads, and I suspect the
same is true of the .net client.

> * Some people advise to create a Channel Pools, is it a good
> practice.

Generally no, because channels are stateful, and thus it's difficult to
ensure that a random channel grabbed from a pool is indeed in the
expected state. This is especially true of things like publisher
confirms, transactions etc.

Matthew
_______________________________________________
rabbitmq-discuss mailing list
rabbitmq...@lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

Reply all
Reply to author
Forward
0 new messages