Bick
Bick

Reputation: 18521

Rabbitmq - multiple binding ( routing keys ) to a single queue

I need a reference please to a multiple routing keys binded queue.
You see, I created a queue and binded it once with

  channel.queuebind()

and another time with yet again

 channel.queuebind()

until i got this two bindings on the same queue.
but upon publishing - only the first bounded message was transfered successfully.
(I even replaced the orders and still - only the first. so my publishing is ok)

What i didnt do - is define the channel.basicConsumer with a new subscriber.
should I do it ? I want the old subsciver to get more messages. what did I do wrong?

Here is a list of my queues is
you can see that amq.gen-4ae4QUbSNevC/RgM+8C9CA== is binded to two keys.

but the message goes only to the first key

 Listing queues ...
 amq.gen-4ae4QUbSNevC/RgM+8C9CA==        0
 amq.gen-sgZK0bSc0W3QEXda8m1vIQ==        0
 PositionsQueue  1
...done.

rabbitmqctl.bat list_bindings

Listing bindings ...
    exchange        PositionsQueue  queue   PositionsQueue  []
    exchange        amq.gen-4ae4QUbSNevC/RgM+8C9CA==        queue   amq.gen-4ae4QUbSNevC/RgM+8C9CA==
    exchange        amq.gen-sgZK0bSc0W3QEXda8m1vIQ==        queue   amq.gen-    sgZK0bSc0W3QEXda8m1vIQ==
    Positions_Exchange      exchange        amq.gen-4ae4QUbSNevC/RgM+8C9CA==        queue   Account:Account1
    Positions_Exchange      exchange        amq.gen-4ae4QUbSNevC/RgM+8C9CA==        queue   Portfolio:Portfolio1
...done.

10x a lot

Edit:

producer

    channel.basicPublish(exchangeName, routingKey, MessageProperties.MINIMAL_BASIC, messageBodyBytes);

consumer

channel.exchangeDeclare(exchangeName, "direct", durable);
QueueName = channel.queueDeclare(queueName, durable, exclusive, autoDelete, arguments).getQueue();
channel.queueBind(queueName, exchangeName, routingKey);

boolean noAck = false;
queueingConsumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, noAck, queueingConsumer);

Upvotes: 12

Views: 28372

Answers (1)

Krunal Saija
Krunal Saija

Reputation: 229

You can follow this way:

channel.queueBind(queueName, exchangeName, "k1"); //k1 is first routing key

channel.queueBind(queueName, exchangeName, "k2"); //k2 is second routing key

Upvotes: 21

Related Questions