Commands | AMQP Publish Messages

Publish Messages

The method PublishMessages is used to send a message to the AMQP server.

 

AMQP Servers automatically bind the queues to "direct" exchange using the queue name as routing key. This allows to send a message to a specific queue without the need to declare a binding (just calling PublishMessage method and pasing the Exchange argument as empty value and the name of the queue in the RoutingKey argument).

 

The method has the following arguments:

 

 


AMQP.PublishMessage('channel_name', 'exchange_name', 'routing_key', 'Hello from sgcWebSockets!!!');
 
procedure OnAMQPBasicReturn(Sender: TObject; const aChannel: string; 
  const aReturn: TsgcAMQPFramePayload_Method_BasicReturn; 
  const aContent: TsgcAMQPMessageContent);
begin
  DoLog('#AMQP_basic_return: ' + aChannel + ' ' + IntToStr(aReturn.ReplyCode) + ' ' + aReturn.ReplyText + ' ' + aContent.Body.AsString);
end;

Publish Confirmations

Network can fail while publishing a message, the only way to guarantee that a message isn't lost is by using transactions, then for each message/s select transaction, send the message and commit. The confirmation of a successful transaction is received when the event OnAMQPTransactionOk is fired.