TsgcWSPClient_AMQPMethods › PublishMessage

PublishMessage Method

Publishes a message to an exchange (basic.publish). Overloaded for string or stream bodies.

Overloads

Overload 1

Syntax

procedure PublishMessage(const aChannel, aExchange, aRoutingKey, aMessage: string; aMandatory: Boolean = false; aImmediate: Boolean = false);

Parameters

NameTypeDescription
aChannelconst stringName of the open AMQP channel on which the operation is issued.
aExchangeconst stringName of the exchange.
aRoutingKeyconst stringRouting key used to match messages published to the exchange.
aMessageconst stringMessage body.
aMandatoryBooleanWhen True the broker returns unroutable messages via basic.return instead of silently dropping them.
aImmediateBooleanWhen True the broker returns a message that cannot be immediately delivered to a consumer.

Remarks

String-body overload. Sends aMessage as the payload, using default basic-properties (content-type and delivery-mode are unset).

Example

sgcWSPClient_AMQP1.PublishMessage('ch1', 'ex.orders', 'orders.new', '{"id":1}');

Overload 2

Syntax

procedure PublishMessage(const aChannel, aExchange, aRoutingKey: string; aMessage: TStream; aMandatory: Boolean = false; aImmediate: Boolean = false);

Parameters

NameTypeDescription
aChannelconst stringName of the open AMQP channel on which the operation is issued.
aExchangeconst stringName of the exchange.
aRoutingKeyconst stringRouting key used to match messages published to the exchange.
aMessageTStreamMessage body.
aMandatoryBooleanWhen True the broker returns unroutable messages via basic.return instead of silently dropping them.
aImmediateBooleanWhen True the broker returns a message that cannot be immediately delivered to a consumer.

Remarks

Stream-body overload. Sends the entire content of aMessage as the payload; useful for binary or large bodies read from a file or memory stream.

Example

vStream := TFileStream.Create('payload.bin', fmOpenRead);
try
  sgcWSPClient_AMQP1.PublishMessage('ch1', 'ex.orders', 'orders.new', vStream);
finally
  vStream.Free;
end;

Back to Methods