Commands | AMQP Channels

AMQP is a multi-channelled protocol. Channels provide a way to multiplex a heavyweight TCP/IP connection into several light weight connections. This makes the protocol more “firewall friendly” since port usage is predictable. It also means that traffic shaping and other network QoS features can be easily employed.

 

Every channel run in his own thread, so every time a new message is received, first the client identifies the channel and queues the message in a queue which is process by the thread channel.

 

The channel life-cycle is this:

 

1. The client opens a new channel (Open).

2. The server confirms that the new channel is ready (Open-Ok).

3. The client and server use the channel as desired.

4. One peer (client or server) closes the channel (Close).

5. The other peer hand-shakes the channel close (Close-Ok).

 

Open Channel

To create a new channel just call the method OpenChannel and pass the channel name as argument. The event OnAMQPChannelOpen is raised as a confirmation sent by the server that the channel has been opened.


AMQP.OpenChannel('channel_name');
 
procedure OnAMQPChannelOpen(Sender: TObject; const aChannel: string);
begin
  DoLog('#AMQP_channel_open: ' + aChannel);
end;

A Synchronous call can be done too calling the method OpenChannelEx, this method returns true if the channel has been opened and false if no confirmation from server has arrived.

 


if AMQP.OpenChannelEx('channel_name') then
  DoLog('#AMQP_channel_open: channel_name');
else
  DoLog('#AMQP_Channel_open_error');

 

Close Channel

To close an existing channel, call the method CloseChannel and pass the channel name as argument. The event OnAMQPChannelClose will be called when the client receives a confirmation that the channel has been closed.

 

A Synchronous call can be done calling the method CloseChannelEx, this method returns true if the channel has been closed and false if no confirmation from server has arrived.

 

 

Channel Flow

Flow control is an emergency procedure used to halt the flow of messages from a peer. It works in the same way between client and server and is implemented by the EnableChannel / DisableChannel commands. Flow control is the only mechanism that can stop an over-producing publisher.

 

To Disable the Flow of a channel, call the method DisableChannel, the event OnAMQPChannelFlow will be called when the client receives a confirmation that the channel flow has been disabled.

The same applies when enabling the flow of a channel, call the method EnableChannel, the event OnAMQPChannelFlow will be called when the client receives a confirmation that the channel flow has been enabled.

 

Synchronous requests are available through the functions EnableChannelEx and DisableChannelEx.