Skip to main content

basic_publish

Publishes a message to a specified exchange and routing key via the AMQP broker. This function handles connection validation, automatic reconnection on failure, and provides feedback on the success or failure of the operation.

def basic_publish(
amqp_context: object,
msg: string,
exchange: string,
routing_key: string,
mandatory: boolean = False,
immediate: boolean = False
) - > null

Publishes a message to a specific exchange with a routing key. This function ensures a connection to the AMQP broker exists before attempting to send the message and handles reconnection on failure.

Parameters

NameTypeDescription
amqp_contextobjectThe application context containing the active AMQP channel, connection state, and logging utilities.
msgstringThe payload content to be sent to the broker.
exchangestringThe name of the exchange to which the message will be published.
routing_keystringThe routing pattern used by the exchange to determine which queues should receive the message.
mandatoryboolean = FalseIf true, the server will return an unroutable message with a Return method; if false, the server silently drops unroutable messages.
immediateboolean = FalseIf true, the server will return an undeliverable message with a Return method if it cannot be delivered immediately to a consumer.

Returns

TypeDescription
nullNo value is returned; the function outputs success or error status to the context's echo interface.