0

In my RabbitMQ, I have an topic exchanger called room-topic-exchange and the bindings are like this enter image description here

When I send a message to an specific queue, using the exchanger, everything works fine. I'm sending as follow:

template.convertAndSend(ROOM_TOPIC_EXCHANGE, roomId, message);

but when I try to send to ALL queues, nothing happens. I'm trying as this

template.convertAndSend(ROOM_TOPIC_EXCHANGE, "room*", message);

I declared the exchanger and the bind as follow

TopicExchange allRooms = new TopicExchange(ROOM_TOPIC_EXCHANGE, false, true);
admin.declareExchange(allRooms);
admin.declareBinding(BindingBuilder.bind(q).to(allRooms).with(roomId));

I can't see what I'm doing wrong. I read the documentantion, and tried with routing key room# too and nothing happened.

Luiz E.
  • 6,769
  • 10
  • 58
  • 98

1 Answers1

1

The topic exchange doesn't work that way; you bind with wildcards, you don't use a wildcard in the routing key.

A queue bound with room.* will get messages sent to room.123 or room.124.

You can achieve what you want by adding a second binding to each room, say room.splat; then sending to room.splat will go to both queues.

Or, you can add a second fanout exchange. Bind both queues to both exchanges (no routing key needed for the fanout) and send broadcasts to the fanout exchange and directed messages to the topic.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Got it! Thanks, @Gary – Luiz E. Nov 25 '15 at 21:36
  • Another question, this second bind should be a direct or can be a topic? – Luiz E. Nov 25 '15 at 21:40
  • 1
    The simplest is 2 exchanges; the one you have and a second `fanout` exchange `bind(q123).to(roomTopicExchange).with("room.123")` and `bind(q123).to(allRoomsFanout)`. Same for the other queue; then `convertAndSend(ROOM_TOPIC, roomid, message` and `convertAndSend(ROOM_FANOUT, "", message)`. – Gary Russell Nov 25 '15 at 21:52