Skip to main content

exchange_declare

Declares an AMQP exchange with the specified name, type, and durability settings via the active channel. This function performs a network call to the broker and automatically attempts to reconnect if the channel is unavailable or an error occurs during declaration.

def exchange_declare(
amqp_context: object,
exchange: string,
type: string,
passive: boolean = False,
durable: boolean = False,
auto_delete: boolean = False
) - > null

Declares an exchange on the AMQP broker, creating it if it does not exist or verifying its existence if the passive flag is set.

Parameters

NameTypeDescription
amqp_contextobjectThe context object containing the active AMQP channel and connection state.
exchangestringThe unique name of the exchange to be declared.
typestringThe exchange type, such as 'direct', 'fanout', 'topic', or 'headers', which determines routing logic.
passiveboolean = FalseIf true, the server will only check if the exchange exists; if it does not, an error is raised.
durableboolean = FalseIf true, the exchange will survive broker restarts.
auto_deleteboolean = FalseIf true, the exchange is deleted when all queues have finished using it.

Returns

TypeDescription
nullNothing is returned; the function outputs the operation status to the console and handles reconnection on failure.