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
| Name | Type | Description |
|---|---|---|
| amqp_context | object | The application context containing the active AMQP channel, connection state, and logging utilities. |
| msg | string | The payload content to be sent to the broker. |
| exchange | string | The name of the exchange to which the message will be published. |
| routing_key | string | The routing pattern used by the exchange to determine which queues should receive the message. |
| mandatory | boolean = False | If true, the server will return an unroutable message with a Return method; if false, the server silently drops unroutable messages. |
| immediate | boolean = False | If true, the server will return an undeliverable message with a Return method if it cannot be delivered immediately to a consumer. |
Returns
| Type | Description |
|---|---|
null | No value is returned; the function outputs success or error status to the context's echo interface. |