AlexGad
AlexGad

Reputation: 6692

RabbitMQ Topic Exchange Message for 1, some or all topics - how to structure it?

I have a message, and need it to be handled by a variable number of queues. The queues handle different purposes - email, audit, webhook processing, s3 storage. Each message can have any, some or all of those topics as targets. For example, I could have the following messages:

Note that although I demonstrated 4 topics, there could potentially be 100s. Can this be handled by a topic exchange? For example, would topic .webhook. miss message 2? Could I add three topics to a queue webhook.*, .webhook. and *.webhook to handle all potential messages, or do I have to know the exact position of where webhook would wind up - ie: ..webhook...* or would .webhook. be sufficient to capture both message 1 and message 3? Can this be handled at all via a topic exchange or am I looking at this all wrong?

EDIT after additional testing

It appears that routing is not as flexible as I was hoping. It appears that in order to do what I want to achieve, I would have to have, for example, a binding for the webhook queue of ..*.webhook, and messages would always have to keep webhook in the 4th position, so a routing key for a message that was only going to webhook, would have to be, as an example "null, null, null, webhook, null, null, etc.

Is my testing correct? I ask because this just does not seem right. I would think there is more flexibility, ie: a better way to accomplish what I want to accomplish.

Upvotes: 0

Views: 352

Answers (1)

robthewolf
robthewolf

Reputation: 7624

I think that the # might help as it allows you to have more than one key. For example:

webhook.#

could be equivalent to:

webhook.*

or

webhook.*.*.*.*.*

or anything inbetween or longer. I have never tried it before a key ie:

#.webhook.#

But that should be something you investigate.

Additionally I think that your problems could be solved by better design of your routing / binding keys. These messages are all going to the same exchange so the should have the same pattern of routing key.

Upvotes: 1

Related Questions