路由密钥不匹配,但仍有消息发送到队列

时间:2018-08-24 14:52:08

标签: go rabbitmq amqp

我正试图让Rabbit向不同的主题发送循环消息。 我有1个名为“ endpoint / 1”的队列 我正在将消息调度到“ endpoint / 1”和“ endpoint / 2”。 “ endpoint / 2”不存在,因此我希望这些消息消失,但是尽管没有绑定,它们仍被发送到队列“ endpoint / 1”事件!

我不知道为什么会这样,我做错什么了吗?

enter image description here enter image description here

// declare exchange
ch.ExchangeDeclare("uop_fanout", "fanout", false, false, false, false, nil)

//send
ch.Publish("uop_fanout", topic, false, false, amqp.Publishing{Body: msg})

// listend
q, err := ch.QueueDeclare(topic, false, false, false, false, nil)
    if err != nil {
        return nil, err
    }
    err = ch.QueueBind(q.Name, topic, "uop_fanout", false, nil)
    if err != nil {
        return nil, err
    }
    messagesFanout, err := ch.Consume(q.Name, "", false, false, false, false, nil)
    if err != nil {
        return nil, err
    }

1 个答案:

答案 0 :(得分:2)

使用以下语句:

ch.ExchangeDeclare("uop_fanout", "fanout", false, false, false, false, nil)

您声明的交换类型为fanout。这意味着到达交易所的消息将被克隆并发送到 all 绑定到该交易所的队列。

“针对不同主题的循环消息”的含义不清楚。

如果您只想进行循环负载平衡,则可以简单地将消息路由到单个队列,并为该队列有两个或多个使用者。

如果要按主题分发邮件,则可以使用带有特定路由键的direct交换。到达的消息将被发送到与匹配的路由密钥绑定的队列。

当然,您可以组合这些概念。

来源:https://www.rabbitmq.com/tutorials/amqp-concepts.html