Azure / amqpnetlite

AMQP 1.0 .NET Library
Apache License 2.0
396 stars 141 forks source link

Guaranteed Transmission #512

Closed CeeSharpDev closed 2 years ago

CeeSharpDev commented 2 years ago

To start with, I am pretty new to Amqp. I have my Solace broker running. And I am using Amqpnetlite Library to establish connection to Solace Amqp. I am able to establish connection and also sending messages.

My objective is to achieve Guaranteed Transmission, which means I would like to see an Acknowledgement once the message is successfully published to the Queue. And for which as per documentation I found "http://azure.github.io/amqpnetlite/api/Amqp.SenderLink.html#implements" a method Send(Message, TimeSpan).

I am still unable to understand, how would I be able to see the Acknowledgement, in order to confirm the message was published and proceed with next message for publishing.

Please find below a simple code snippet I am currently following up for Publishing Message To Queue

// Establish Connection
Address address = new Address($"amqp://{UserName}:{Password}@{Host}");
Connection connection = new Connection(address); 
Session session = new Session(connection);

// Send Message
var message = new Message(jsonByteArray);
SenderLink sender = new SenderLink(session, "sender-link", "exampleQueue");
sender.Send(message, TimeSpan.FromMilliseconds(20000)); 

// Close connection
sender.Close();
session.Close();
connection.Close();

I would really appreciae, if someone could guide me here to proceed further.

Havret commented 2 years ago

Hi @CeeSharpDev

When you call Send on SenderLink it will synchronously block until the other party sends ack (or throw TimeoutException if no ack received). That's the default behavior, for the mentioned overload.

Please take a look here for more details. --> https://github.com/Azure/amqpnetlite/blob/master/src/SenderLink.cs#L110

CeeSharpDev commented 2 years ago

Hi @Havret

so when an message is received by the broker, does SenderLink.LinkState = Accepted mean that broker has accepted and Acknowledged the message?

Havret commented 2 years ago

No, when Send returns it means that the broker has ack'ed the message. That's the default behaviour.

CeeSharpDev commented 2 years ago

Okay, understood now. Thank you @Havret for your quick reply. 👍 :)