开发者

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

开发者 https://www.devze.com 2023-02-21 00:12 出处:网络
I need a reference please to a multiple routing keys binded queue. You see, I created a queue and binded it once with

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);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号