I need to call the RabbitMQ RPC service from a C # WCF web service hosted in IIS. We are working fine, but as a good little soldier, I read the RabbitMQ client documentation and it states the following "IModel should not be shared between threads . "
I understand that in RabbitMQ, the IModel is actually a socket connection. this means that for each call, the WCF service forces it to create an IModel and delete it after completion.
It seems to me that I'm somewhat excessive in performance and use of sockets, and I'm wondering if my understanding is really correct or if there are other options available, such as using the connection pool for IModels between threads.
Any suggestions would be greatly appreciated. Here is the sample code that I use below, the rabbitMQ connection is actually initialized in Global.asax, I just see it there, you can see the usage.
var connectionFactory = new ConnectionFactory(); connectionFactory.HostName = "SampleHostName"; connectionFactory.UserName = "SampleUserName"; connectionFactory.Password = "SamplePassword"; IConnection connection = connectionFactory.CreateConnection(); // Code below is what we actually have in the service method. var model = connection.CreateModel(); using (model) { model.ExchangeDeclare("SampleExchangeName", ExchangeType.Direct, false); model.QueueDeclare("SampleQueueName", false, false, false, null); model.QueueBind("SampleQueueName", "SampleExchangeName", "routingKey" , null); // Do stuff, like post messages to queues }
source share