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
| Attribute | Type | Description |
|---|---|---|
| cli_context | object | The command-line interface context used to access the application instance and perform output operations. |
| connection | connection object | The active AMQP connection instance used to communicate with the message broker. |
| channel | channel object = null | The communication channel established on the current connection for executing AMQP commands. |
Constructor
Signature
def AMQPContext(
cli_context: object
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| cli_context | object | The command-line interface context object providing application and connection details. |
Signature
def AMQPContext(
cli_context: object
)
Parameters
| Name | Type | Description |
|---|---|---|
| cli_context | object | The 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
| Type | Description |
|---|---|
object | The 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
| Name | Type | Description |
|---|---|---|
| retval | any | The value or object to be displayed to the user via the CLI output. |
Returns
| Type | Description |
|---|---|
null |
echo_error()
@classmethod
def echo_error(
exception: Exception
) - > null
Displays a formatted error message to the CLI when an exception occurs.
Parameters
| Name | Type | Description |
|---|---|---|
| exception | Exception | The exception object or error message to be reported to the user. |
Returns
| Type | Description |
|---|---|
null |
echo_ok()
@classmethod
def echo_ok() - > null
Prints a standard success indicator to the CLI to signal a completed operation.
Returns
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
null |