ab_732
ab_732

Reputation: 3897

RabbitMQ header exchange with list

I am having some issues trying to understand how an exchange of type headers works.

Only one exchange, myExchange

Three queues:

  1. myQueue1
  2. myQueue2
  3. myQueue3

Bindings:

  1. myExchange => myQueue1 (x-match: any, myHeader: [test1])
  2. myExchange => myQueue2 (x-match: any, myHeader: [test2])
  3. myExchange => myQueue3 (x-match: any, myHeader: [test1, test2, test3])

I am expecting the header of the message to have multiple values; any combination of test1, test2, test3 (example: test1 alone, test1 and test2, test3 and test2, etc...)

myQueue3 only receives messages if they have myHeaders:[test1, test2, test3]. I would expect myQueue3 to get messages for, e.g. test1 and test2 as well.

myQueue1 only receives messages if they have myHeaders:[test1]. I would expect myQueue1 to get messages for, e.g. test1 and [test1, test2] as well.

Is there any way to achieve such behavior? Thank you

Upvotes: 2

Views: 3368

Answers (3)

Sylvain Lecoy
Sylvain Lecoy

Reputation: 1017

You can declare multiple bindings for the same queue.

In your case the queue 3 will have three different bindings.

Multiple bindings

Upvotes: 1

vernou
vernou

Reputation: 7590

For this, I have a trick.

Bindings:

  • myExchange => myQueue1 (x-match: any, test1: true)
  • myExchange => myQueue2 (x-match: any, test2: true)
  • myExchange => myQueue3 (x-match: any, test1: true, test2: true, test3: true)

myQueue1 will receive all message with header containts {test1: true}.

myQueue2 will receive all message with header containts {test2: true}.

myQueue3 will receive all message with header containts one of this {test1: true}, {test2: true} or {test3: true}.

I prefer this, because Routing Key is limited by 255 bytes, but the limit of number of elements in header is very higth.

For performance, I don't know what it's the best.

Upvotes: 1

ab_732
ab_732

Reputation: 3897

I agree with the comments, I was trying to achieve something that at the moment is not supported. I will use routing keys.

Upvotes: 0

Related Questions