duan1989643
2018-08-24 14:52
浏览 74
已采纳

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

Im trying to get rabbit to send round robin messages to different topics. I have 1 queue called "endpoint/1" I am dispatching messages to "endpoint/1" and "endpoint/2". "endpoint/2" does not exists so i expected those messages to disappear but instead they get sent to the queue "endpoint/1" event though there is no binding to it!

I have no idea why this is happening, am i doing something wrong?

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
    }

图片转代码服务由CSDN问答提供 功能建议

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

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

”在此处输入图片描述“ ”在此处输入图片描述“

  //声明exchange 
ch.ExchangeDeclare(“ uop_fanout”,“ fanout”,false,false,false,false,nil)
 
 //发送
ch  .publish(“ uop_fanout”,topic,false,false,amqp.Publishing {Body:msg})
 
 //听过
q,错误:= ch.QueueDeclare(topic,false,false,false,false,nil  )
 if err!= nil {
返回nil,err 
} 
 err = ch.QueueBind(q.Name,topic,“ uop_fanout”,false,nil)
如果err!= nil {
  RET  urn nil,err 
} 
 messagesFanout,err:= ch.Consume(q.Name,“”,false,false,false,false,nil)
如果err!= nil {
返回nil,err \  n} 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dssnh86244 2018-08-24 17:23
    已采纳

    With this statement:

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

    you are declaring an exchange of type fanout. This means messages arriving at the exchange get cloned and sent to all the queues bound to that exchange.

    It's not clear what you mean by "round robin messages to different topics".

    If you want to do just round-robin load balancing, you can simply route your messages to a single queue, and have two or more consumers for that queue.

    If you want to distribute messages by topic, you can use a direct exchange, with specific routing keys. An arriving message will be sent to the queue bound with the matching routing key.

    Of course, you can combine those concepts.

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

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题