In the AMQP 1.0.0 protocol, a Receiver Link is a communication channel established between an AMQP client and an AMQP server for the purpose of receiving messages. It operates within the context of an AMQP session, which represents a logical channel for communication between the client and server.
To Create a new Receiver Link, call the method CreateReceiverLink which contains the following parameters:
amqp1srmAuto: Automatic Mode, in this mode the receiver actively works to ensure that messages are received promptly as soon as they become available. It automatically listens for and receives messages without any explicit instruction each time a new message arrives.
amqp1srmManual: Fetch-Based Mode, in this mode, the receiver will only retrieve or fetch a new message when it is specifically told to do so. Unlike the automatic mode, the receiver will not actively listen for new messages but will instead wait for manual instructions to fetch the next message.
amqp1rsmFirst: When messages arrive, they will be processed and confirmed right away. If the message hasn't already been confirmed by the time it was sent, the sender will be informed that the message has been received.
amqp1rsmSecond: Messages that arrive will only be confirmed after the sender has confirmed them first. Additionally, the sender will receive a notification when a message has been received, provided the message wasn't already confirmed when it was sent.
When the Receiver Link has been created successfully, the event OnAMQPLinkOpen will be fired.
oAMQP1.CreateReceiverLink('MySession', 'MyReceiverLink');
procedure procedure TfrmClientAMQP1.AMQP1AMQPLinkOpen(Sender: TObject; const aSession: TsgcAMQP1Session; const aLink: TsgcAMQP1Link; const aAttach: TsgcAMQP1FrameAttach);
begin
ShowMessage('#link-open: ' + aLink.Name);
end;
Await Create Receiver Link
By default, the CreateReceiverLink method is Asynchronous, so after calling the method, the code continue. If you want to wait till the CreateReceiverLink method is completed and the confirmation sent by the server is received, set the property Await to True in the Options parameter.
procedure CreateReceiverLink(const aSession, aReceiver: string);
var
oOptions: TsgcAMQP1MethodOptions_CreateReceiverLink;
begin
oOptions := TsgcAMQP1MethodOptions_CreateReceiverLink.Create;
Try
oOptions.Await := True;
AMQP1.CreateReceiverLink(aSession, aReceiver, '', oOptions);
Finally
oOptions.Free;
End;
end;
When the Receiver Link works in Manual ReadMode, call the method GetMessage to get new messages. This method is synchronous, which means that waits till a timeout is exceeded (by default 10 seconds). When the method is called, the component increases the credit in one unit and waits till a new message arrives or the timeout has been exceeded. If no message arrives, the credit is set to zero again.
The method GetMessage has the following parameters:
To Close an existing Receiver Link, call the method CloseLink which contains the following parameters:
When the Receiver Link has been closed successfully, the event OnAMQPLinkClose will be fired.
oAMQP1.CloseLink('MySession', 'MyReceiverLink');
procedure OnAMQPLinkCloseEvent(Sender: TObject; const aSession: TsgcAMQP1Session; const aLink: TsgcAMQP1Link; const aDetach: TsgcAMQP1FrameDetach);
begin
ShowMessage('#link-close: ' + aLink.Name);
end;
Await Close Receiver Link
By default, the CloseLink method is Asynchronous, so after calling the method, the code continue. If you want to wait till the CloseLink method is completed and the confirmation sent by the server is received, set the property Await to True in the Options parameter.
procedure CloseReceiverLink(const aSession, aReceiverLink: string);
var
oOptions: TsgcAMQP1MethodOptions_CloseLink;
begin
oOptions := TsgcAMQP1MethodOptions_CloseLink.Create;
Try
oOptions.Await := True;
AMQP1.CloseLink(aSession, aReceiverLink, oOptions);
Finally
oOptions.Free;
End;
end;