dongqiuqiu4736 2015-03-05 18:28
浏览 20

如何验证发布者确认行为

I am writing a go program with publisher confirms, and I want to verify the behavior when a message can be delivered/not be delivered to the broker.

I am doing this from an integration test that sets up a queue, and asks my system code to send to that queue name. Verifying the behavior for publisher ack is no problem, but I cannot provoke a situation that results in a publisher nack.

I try to send a message to a non-existing queue with the following piece of code:

connection, err := amqp.Dial("amqp://localhost")
if err != nil {
    panic(err)
}
defer connection.Close()
channel, err := connection.Channel()
if err != nil {
    panic(err)
}
err = channel.Confirm(false)
if err != nil {
    panic(err)
}
pubAck, pubNack := channel.NotifyConfirm(make(chan uint64, 1), make(chan uint64, 1))
fmt.Println("Publish to queue: ", queueName)
msg := amqp.Publishing{
    Body: []byte("Hello")}
err = channel.Publish("", queueName, true, true, msg)
if err != nil {
    panic(err)
}
select {
case <-pubAck:
    fmt.Println("Ack")
case <-pubNack:
    fmt.Println("NAck")
}

The queue name is indeed a non existing queue, and executing sudo rabbitmqctl list_queues shows that the list of queues is empty.

But it still prints "Ack"

I have set both mandatory and immediate to true

Publishings can be undeliverable when the mandatory flag is true and no queue is bound that matches the routing key, or when the immediate flag is true and no consumer on the matched queue is ready to accept the delivery

Is my approach for sending to a non-existing queue a wrong approach, and is there another way I can send a message that will provoke a publisher nack?

  • 写回答

1条回答 默认 最新

  • duangaixing1509 2015-03-05 18:45
    关注

    RabbitMQ will only return a basic.nack if

    an internal error occurs in the Erlang process responsible for a queue.

    So, the basic.ack/basic.nack is only confirming if the RabbitMQ broker received the message, not if a "final" consumer did. See the last sentence of "Negative Acknowledgement" on this page.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据