Read first AMQP1 Sender Links to know how to create a Sender Link.
Use the method SendMessage passing the Session and SenderLink name to send a text message to the AMQP1 Server. The method has the following parameters:
oAMQP1.SendMessage('MySession', 'MySenderLink', 'My first AMQP Message');
By default, the SendMessage method is asynchronous when sending a message unsettled, setting the property Await to true, the client will wait till receives a confirmation from the server that the message has been processed.
procedure SendMessageAwait(const aSession, aSenderLink, aText: string);
var
oOptions := TsgcAMQP1MethodOptions_SendMessageAck.Create;
begin
Try
oOptions.Settled := False;
oOptions.Await := True;
AMQP1.SendMessage(aSession, aSenderLink, aText, 'messsage-id', oOptions);
Finally
oOptions.Free;
End;
end;
When sending a message, there are 2 Events that can be used to know when the message is sent and if the message has been processed by the server (when sending unsettled).
procedure OnAMQPMessageSentAck(Sender: TObject;
const aSession: TsgcAMQP1Session; const aLink: TsgcAMQP1SenderLink;
const aMessageId: string; const aDeliveryState: TsgcAMQP1FrameDeliveryStates;
const aDisposition: TsgcAMQP1FrameDisposition);
var
vMessageId: string;
begin
vMessageId := aMessageId;
case aDeliveryState of
amqp1fdtsAccepted:
ShowMessage('#msg-accepted: ' + vMessageId);
amqp1fdtsRejected:
ShowMessage('#msg-rejected: ' + vMessageId + ' ' + TsgcAMQP1FrameRejected
(aDisposition.State).Error.Condition + ' ' + TsgcAMQP1FrameRejected
(aDisposition.State).Error.Description);
amqp1fdtsReleased:
ShowMessage('#msg-released: ' + vMessageId);
amqp1fdtsModified:
ShowMessage('#msg-modified: ' + vMessageId + ' ' + TsgcAMQP1FrameModified
(aDisposition.State).MessageAnnotations);
amqp1fdtsReceived:
ShowMessage('#msg-received: ' + vMessageId);
end;
end;