Commands | AMQP Get Messages

Getting messages is a Synchronous task, which means that is the client who ask to server is there are messages in the queue. You can read an alternative method to Receive Message Aynchronously.

 

Get Message

The method GetMessage sends a request to the AMQP server asking if there are messages available in a queue. If there are messages these will be dispatched OnAMQPBasicGetOk event and if the queue is empty, the event OnAMQPBasicGetEmpty will be called.

 

The method has the following arguments:

 

 


AMQP.GetMessage('channel_name', 'queue_name');
 
procedure OnAMQPBasicGetOk(Sender: TObject; const aChannel: string; 
  const aGetOk: TsgcAMQPFramePayload_Method_BasicGetOk; 
  const aContent: TsgcAMQPMessageContent);
begin
  DoLog('#AMQP_basic_GetOk: ' + aChannel + ' ' + IntToStr(aGetOk.MessageCount) + ' ' + aContent.Body.AsString);
end;
 
procedure OnAMQPBasicGetEmpty(Sender: TObject; const aChannel: string);
begin
  DoLog('#AMQP_basic_GetEmpty: ' + aChannel);
end;

A Synchronous call can be done just calling the method GetMessageEx, this method returns true if the queue has messages available, otherwise the result will be false.