Commands | AMQP1 Sender Links

In the AMQP 1.0.0 protocol, a Sender Link is a communication channel established between an AMQP client and an AMQP server for the purpose of sending messages. It operates within the context of an AMQP session, which represents a logical channel for communication between the client and server.

 

Create Sender Link

To Create a new Sender Link, call the method CreateSenderLink which contains the following parameters:

 

 

When the Sender Link has been created successfully, the event OnAMQPLinkOpen will be fired.

 

oAMQP1.CreateSenderLink('MySession', 'MySenderLink');
procedure procedure TfrmClientAMQP1.AMQP1AMQPLinkOpen(Sender: TObject; const aSession: TsgcAMQP1Session; const aLink: TsgcAMQP1Link; const aAttach: TsgcAMQP1FrameAttach);
begin
  ShowMessage('#link-open: ' + aLink.Name);
end;

 

Await Create Sender Link

 

By default, the CreateSenderLink method is Asynchronous, so after calling the method, the code continue. If you want to wait till the CreateSenderLink method is completed and the confirmation sent by the server is received, set the property Await to True in the Options parameter.

 


procedure CreateSenderLink(const aSession, aSender: string);
var
  oOptions: TsgcAMQP1MethodOptions_CreateSenderLink;
begin
  oOptions := TsgcAMQP1MethodOptions_CreateSenderLink.Create;
  Try
    oOptions.Await := True;
    AMQP1.CreateSenderLink(aSession, aSender, '', oOptions);
  Finally
    oOptions.Free;
  End;
end;

 

Sending Messages

To Send a new Message, call the method SendMessage which contains the following parameters:

 

 


oAMQP1.SendMessage('MySession', 'MySenderLink', 'My first AMQP Message');

 

Sending Messages Mixed Mode

When the Sender Link is created in Mixed mode (the default), when sending a message, the user can set if want the message is settled or not. Use the MessageOptions parameter to define if the message is settled or not.

 


oMessageOptions := TsgcAMQP1MessageOptions.Create;
Try
  oMessageOptions.Settled := True;
  oAMQP1.SendMessage('MySession', 'MySenderLink', 'MyMessage', 'message-id', oMessageOptions);
Finally
  oMessageOptions.Free;
End;

 

Close Sender Link

To Close an existing Sender Link, call the method CloseLink which contains the following parameters:

 

 

When the Sender Link has been closed successfully, the event OnAMQPLinkClose will be fired.


oAMQP.CloseLink('MySession', 'MySenderLink');
procedure OnAMQPLinkCloseEvent(Sender: TObject; const aSession: TsgcAMQP1Session; const aLink: TsgcAMQP1Link; const aDetach: TsgcAMQP1FrameDetach);
begin
  ShowMessage('#link-close: ' + aLink.Name);
end;

Await Close Sender 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 CloseSenderLink(const aSession, aSenderLink: string);
var
  oOptions: TsgcAMQP1MethodOptions_CloseLink;
begin
  oOptions := TsgcAMQP1MethodOptions_CloseLink.Create;
  Try
    oOptions.Await := True;
    AMQP1.CloseLink(aSession, aSenderLink, oOptions);
  Finally
    oOptions.Free;
  End;
end;