AMQP.Basic.get/3 option no_ack: true not working
Closed this issue · 2 comments
bbtdev commented
Hi,
So the get method acknowledges the messages no matter the option I set:
iex(25)> HelloWorldPublisher.test_publish "first"
:ok
iex(26)> HelloWorldPublisher.test_publish "second"
:ok
iex(27)> AMQPBasic.get(channel, "local:helloworld", no_ack: true)
{:ok, "first",
%{
app_id: :undefined,
cluster_id: :undefined,
content_encoding: :undefined,
content_type: :undefined,
correlation_id: :undefined,
delivery_tag: 7,
exchange: "local:hello-world",
expiration: :undefined,
headers: :undefined,
message_count: 1,
message_id: :undefined,
persistent: false,
priority: :undefined,
redelivered: false,
reply_to: :undefined,
routing_key: "notifications-hello-world",
timestamp: :undefined,
type: :undefined,
user_id: :undefined
}}
iex(28)> AMQPBasic.get(channel, "local:helloworld", no_ack: true)
{:ok, "second",
%{
app_id: :undefined,
cluster_id: :undefined,
content_encoding: :undefined,
content_type: :undefined,
correlation_id: :undefined,
delivery_tag: 8,
exchange: "local:hello-world",
expiration: :undefined,
headers: :undefined,
message_count: 0,
message_id: :undefined,
persistent: false,
priority: :undefined,
redelivered: false,
reply_to: :undefined,
routing_key: "notifications-hello-world",
timestamp: :undefined,
type: :undefined,
user_id: :undefined
}}
iex(29)> AMQPBasic.get(channel, "local:helloworld", no_ack: true)
{:empty, %{cluster_id: ""}}
ono commented
like the document I shared above says, no_ack means "If this field is set the server does not expect acknowledgements for messages."
i understand it's a bit confusing but this library doesn't have any control over the protocol. If you want to get the message and return it back to the queue, you shouldn't set the option. Instead, you might want to use nack for the message.