[rabbitmq-discuss] IModel thread safety in.NET client

Emile Joubert emile at rabbitmq.com
Thu Oct 13 13:35:50 BST 2011


Hi,

On 12/10/11 20:29, TrueWill wrote:
> The .NET client user guide (v2.6.1) states that IModel should not be
> shared between threads.
> 
> Apparently BasicAck must be called on the same channel on which the
> message was received.
> 
> When asynchronously consuming messages with IBasicConsumer, is it safe
> to call BasicAck on the original channel (created on the application
> thread) in the handler without locking?

Yes, asynchronous methods such as ack and publish are safe.

> I'm assuming that the handler runs on the connection thread.
> 
> I realize that publish should not be called in the handler. If publish
> can be called by the application thread, should that be done on a
> separate channel from the consuming one?

You can use publish from the same channel or from a separate channel.
You must ensure that you do not invoke blocking methods (that wait for a
reply from the broker) in a handler. QueueDeclare and BasicCancel are
examples of methods that will cause deadlock.


-Emile


More information about the rabbitmq-discuss mailing list