PublishMessages 方法用于向 AMQP 服务器发送消息。
AMQP 服务器使用队列名称作为路由键自动将队列绑定到"direct"交换机。这允许向特定队列发送消息而无需声明绑定(只需调用 PublishMessage 方法,将 Exchange 参数设为空值,将队列名称作为 RoutingKey 参数传入)。
Publish Messages
该方法具有以下参数:
- ChannelName:通道名称(调用此方法前必须已打开)。
- ExchangeName:交换机名称,不得超过 255 个字符,且不能以"amq."开头(除非 passive 参数为 true)。
- RoutingKey:绑定的路由键名称。
- Mandatory:如果为 true 且消息无法路由到任何队列,服务器将返回该消息,触发 OnAMQPBasicReturn 事件。
- Immediate:如果为 true 且消息无法路由到任何队列,服务器将返回该消息,触发 OnAMQPBasicReturn 事件。
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;
