Commands | AMQP1 Receiver Links

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.

 

Create Receiver Link

To Create a new Receiver Link, call the method CreateReceiverLink which contains the following parameters:

 

 

 

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;

 

Sync Messages

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:

 

 

Close Receiver Link

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;