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.
To Create a new Sender Link, call the method CreateSenderLink which contains the following parameters:
amqp1ssmSettled: The message is considered successfully delivered and acknowledged once it's sent.
amqp1ssmUnsettled: The message is not considered settled until it's explicitly accepted or rejected by the receiver. This allows for more control over message processing and handling.
amqp1ssmMixed: A combination of settled and unsettled modes can be used within a single AMQP session. Use the MessageOptions parameter of the SendMessage method to configure if the message is Settled or not.
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;
To Send a new Message, call the method SendMessage which contains the following parameters:
oAMQP1.SendMessage('MySession', 'MySenderLink', 'My first AMQP Message');
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;
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;