Re: consumer received message from a queue it's not bound to? [c# rabbitmq-client, iis, servicestack]

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: consumer received message from a queue it's not bound to? [c# rabbitmq-client, iis, servicestack]

Mariusz Wojcik
Hi Steve,

    This probably happens because both queues are bound to the exchange to receive a message. The reason for that may be an exchange type (fan-out for example will send message to any bound queue) or routing-key. Looking at your example, the routing-key used to bind queues is empty. Hence each message post with empty routing key will be delivered to both queues. You can run simple test to verify that. Just make sure all your queues are set up and then publish a message but do not run any consumers. Login to management portal to check to which queue the message has been routed to.

You can find more information about routing-key at [http://www.rabbitmq.com/amqp-0-9-1-reference.html#queue.bind.routing-key](http://www.rabbitmq.com/amqp-0-9-1-reference.html#queue.bind.routing-key)

Cheers,

Mariusz


On Wednesday, 16 July 2014 21:45:04 UTC+1, Steve Schoon wrote:
Here is my strange problem that I can't figure out how to fix:
  • consumer 1 write message 'a' to 'work-queue'
  • worker starts processing job 'a' (this takes a few minutes)
  • consumer 1 subscribes to 'queue-a' and try to consume 1 msg
  • consumer 2 subscribes to 'queue-b' and tries to consume 1 msg
  • worker completes processing job 'a'
  • worker writes 'a-is-done' message to 'queue-a'
  • ** CONSUMER 2 RECEIVES THE 'a-is-done' WRITTEN TO 'queue-a' EVEN THOUGH IT'S CONSUMING FROM 'queue-b'
  • consumer 1 receives the expected message from 'queue-a'
  • worker starts processing job 'b'
  • worker completes processing job 'b'
  • worker writes 'b-is-done' message to 'queue-'b
'worker' is a console application that does the following in a forever loop:
  • reads 1 message from 'work-queue', 
  • does some processing
  • write 1 message to 'queue-X' where 'X' is part of the message it read from 'work-queue'

'consumer1' and 'consumer2' are requests being handled by a a ServiceStack-based webservice running under IIS 7.5.  The code looks like this:

string queueName = request.QueueName;
BasicDeliverEventArgs result = null;
var connectionFactory = new ConnectionFactory();
connectionFactory.Endpoint = new AmqpTcpEndpoint("myhostname");
connectionFactory.UserName = "user";
connectionFactory.Password = "pass";
using (IConnection connection = connectionFactory.CreateConnection())
{
using (IModel channel = connection.CreateModel())
{
channel.ExchangeDeclare("myexchange", ExchangeType.Direct, true);
channel.QueueDeclare(queueName, false, false, true, null);
channel.QueueBind(queueName, "myexchange", "");
using (Subscription sub = new Subscription(channel, "queue-a", false))
{
bool rc = sub.Next(60 * 5 * 1000, out result);
if (rc == false && result == null)
{
throw new Exception("whatever");
}
sub.Ack(result);
}
}
}
string msg = Encoding.UTF8.GetString(result.Body);

How is is possible that when subscribed to 'queue-a', that a message is received that we placed into 'queue-b'?

Hope this makes sense....thanks for any thoughts/suggestions.

--
Steve Schoon

_______________________________________________
rabbitmq-discuss mailing list has moved to https://groups.google.com/forum/#!forum/rabbitmq-users,
please subscribe to the new list!

[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss