Skip to main content

AMQPContext

This class manages the lifecycle and communication state of an AMQP connection within a command-line interface context. It provides methods for establishing and refreshing connections, accessing the default communication channel, and formatting responses or errors for the user. By wrapping the underlying connection, it simplifies interaction between the application's messaging backend and the CLI output.

Attributes​

AttributeTypeDescription
cli_contextobjectThe command-line interface context used to access the application instance and perform output operations.
connectionconnection objectThe active AMQP connection instance used to communicate with the message broker.
channelchannel object = nullThe communication channel established on the current connection for executing AMQP commands.

Constructor​

Signature​

def AMQPContext(
cli_context: object
) - > null

Parameters​

NameTypeDescription
cli_contextobjectThe command-line interface context object providing application and connection details.

Signature​

def AMQPContext(
cli_context: object
)

Parameters​

NameTypeDescription
cli_contextobjectThe command-line interface context providing access to the application instance and output methods.

Methods​


app()​

@classmethod
def app() - > object

Retrieves the application instance associated with the current CLI context.

Returns​

TypeDescription
objectThe application object containing configuration and connection factory methods.

respond()​

@classmethod
def respond(
retval: any
) - > null

Outputs a return value to the CLI, formatting non-string objects using pretty-print for readability.

Parameters​

NameTypeDescription
retvalanyThe value or object to be displayed to the user via the CLI output.

Returns​

TypeDescription
null

echo_error()​

@classmethod
def echo_error(
exception: Exception
) - > null

Displays a formatted error message to the CLI when an exception occurs.

Parameters​

NameTypeDescription
exceptionExceptionThe exception object or error message to be reported to the user.

Returns​

TypeDescription
null

echo_ok()​

@classmethod
def echo_ok() - > null

Prints a standard success indicator to the CLI to signal a completed operation.

Returns​

TypeDescription
null

reconnect()​

@classmethod
def reconnect() - > null

Closes any existing connection and attempts to establish a new connection to the AMQP broker, updating the active channel.

Returns​

TypeDescription
null