【问题标题】:RabbitMQ header exchange with listRabbitMQ 标头与列表交换
【发布时间】:2015-05-03 13:54:14
【问题描述】:

我在试图理解 headers 类型的交换如何工作时遇到了一些问题。

只有一个交易所,myExchange

三个队列:

  1. 我的队列1
  2. 我的队列2
  3. 我的队列3

绑定:

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

我希望消息的标题有多个值; test1test2test3 的任意组合(例如:单独的 test1test1test2test3test2等...)

myQueue3 仅接收具有 myHeaders:[test1, test2, test3] 的消息。我希望 myQueue3 能够获取消息,例如test1test2 也是如此。

myQueue1 仅接收具有 myHeaders:[test1] 的消息。我希望 myQueue1 能够获取消息,例如test1 和 [test1, test2] 也是如此。

有没有办法实现这种行为?谢谢

【问题讨论】:

  • 看起来标头交换绑定不能以这种方式工作。 AFAIR,他们使用严格匹配,所以如果你有一些标题的数组值,那么该数组中的项目位置很重要。也许使用带有(多个)通配符路由键绑定的常规主题交换会更好地为您服务?
  • 使用路由密钥对您的情况有所帮助。

标签: rabbitmq message-queue rabbitmq-exchange


【解决方案1】:

为此,我有一个窍门。

绑定:

  • 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 将接收所有标头包含 {test1: true} 的消息。

myQueue2 将接收所有标头包含 {test2: true} 的消息。

myQueue3 将接收所有标头包含 {test1: true}、{test2: true} 或 {test3: true} 之一的消息。

我更喜欢这个,因为 Routing Key 有 255 个字节的限制,但是 header 中的元素数量限制非常高。

对于性能,我不知道它是最好的。

【讨论】:

  • 主题交换比标题快。
【解决方案2】:

我同意 cmets,我试图实现目前不受支持的东西。我将使用路由键。

【讨论】:

    猜你喜欢
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    相关资源
    最近更新 更多