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?