AMQP allows to receive the messages in 2 modes:
Consumers consume from queues. In order to consume messages there has to be a queue. When a new consumer is added, assuming there are already messages ready in the queue, deliveries will start immediately.
The target queue can be empty at the time of consumer registration. In that case first deliveries will happen when new messages are enqueued.
Consuming messages is an asynchronous task, which means that every time a new message can be delivered to the consumer queue, it's pushed by the server to the client automatically. You can read an alternative method to Receive Message Synchronously.
The method Consume creates a new consumer in the queue, and every time there is a new message this will be delivered automatically to the consumer client.
The method has the following arguments:
The messages are delivered OnAMQPBasigGetOk event.
AMQP.Consume('channel_name', 'exchange_name', 'consumer_tag'); 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;
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.
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', 'exchange_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;
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.