The exchange class lets an application manage exchanges on the server. This class lets the application script its own wiring (rather than relying on some configuration interface). Note: Most applications do not need this level of sophistication, and legacy middleware is unlikely to be able to support this semantic.
The exchange life-cycle is:
1. The client asks the server to make sure the exchange exists (Declare). The client can refine this into, "create the exchange if it does not exist", or "warn me but do not create it, if it does not exist".
2. The client publishes messages to the exchange.
3. The client may choose to delete the exchange (Delete).
This method creates a new exchanges or verifies that an Exchange already exists. The method has the following arguments:
To Declare a new Exchange just call the method DeclareExchange and pass the channel name, exchange name and exchange type as arguments. The event OnAMQPExchangeDeclare is raised as a confirmation sent by the server that the exchange has been declared.
AMQP.DeclareExchange('channel_name', 'exchange_name', 'direct');
procedure OnAMQPExchangeDeclare(Sender: TObject; const aChannel, aExchange: string);
begin
DoLog('#AMQP_exchange_declare: [' + aChannel + '] ' + aExchange);
end;
A Synchronous call can be done too calling the method DeclareExchangeEx, this method returns true if the Exchange has been Declared and false if no confirmation from server has arrived.
if AMQP.DeclareExchangeEx('channel_name', 'exchange_name', 'direct') then
DoLog('#AMQP_exchange_declare: [' + aChannel + '] ' + aExchange);
else
DoLog('#AMQP_exchange_declare_error');
This method is used to delete an existing Exchange. The method has the following arguments:
To Delete an existing Exchange call the method DeleteExchange and pass the channel name and exchange name as arguments. The event OnAMQPExchangeDelete is raised as a confirmation sent by the server that the exchange has been deleted.
A Synchronous call can be done too calling the method DeleteExchangeEx, this method returns true if the Exchange has been Deleted and false if no confirmation from server has arrived.