AMQP Publish Messages (2 / 3)

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).

Publish Messages 

The method has the following arguments:

  • ChannelName: it's the name of the channel (must be open before call this method).
  • ExchangeName: it's the name of the exchange, must be no longer of 255 characters and not begin with "amq." (except if passive parameter is true).
  • RoutingKey: it's the binding's routing key name.
  • Mandatory: if true and the message cannot be routed to any queue, the message is returned by the server, the event OnAMQPBasicReturn is fired.
  • Immediate: if true and the message cannot be routed to any queue, the message is returned by the server, the event OnAMQPBasicReturn is fired.
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; 
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

AMQP Receive Messages (3 / 3)
AMQP Exchanges and Queues (1 / 3)

Related Posts