extras.rabbit_mq — RabbitMQ Container Service


A YellowService that runs the messaging queue RabbitMQ. Uses the official docker container, with Pika as the Python client implementation.

Note

Requires the rabbit extra. For more information, see our installation guide.

class extras.rabbit_mq.RabbitMQService(docker_client: DockerClient, image: str = 'rabbitmq:latest', *, user: str = 'guest', password: str = 'guest', virtual_host: str = '/', enable_management: bool = False, container_create_kwargs: dict[str, Any] | None = None, **kwargs)[source]

A service that runs a rabbitmq queue. Inherits from SingleContainerService. Usable with RunMixin and AsyncRunMixin.

Parameters:
  • docker_client – The docker client to used to pull and create the RabbitMQ container.

  • image – The image name to create a container of.

  • user – The username to of the default credentials.

  • password – The username to set as the default credentials.

  • virtual_host – The virtual host to use in multi-tenant system. For more information see the appropriate documentation.

  • enable_management – If set to true, rabbitMQ management will be automatically enabled for the service.

  • container_create_kwargs – Additional keyword arguments passed to docker.models.containers.ContainerCollection.create().

  • **kwargs – Additional keyword arguments passed to SingleContainerService.

Has the following additional methods:

connection_port() int[source]

Returns the connection port for external access from the docker host.

connection(**kwargs) BlockingConnection[source]
Parameters:

**kwargs – Additional keyword arguments passed to pika.connection.ConnectionParameters use to create the connection.

Returns a connected pika connection to the rabbitMQ queue.

enable_management()[source]

Enables the RabbitMQ Management plugin.

Note

The RabbitMQService must be running to enable management.

management_url() str[source]

Returns the localhost RabbitMQ Management URL.

Note

Before connecting, make sure management is enabled using enable_management().

reset_state(force_queue_deletion: bool = False)[source]

Remove all declared RabbitMQ queues.

Parameters:

force_queue_deletion (bool) – If True, queues will be deleted regardless of other open consumers currently attached to the queues. Otherwise, removal of the queue will raise a requests.HTTPError.

Note

Before connecting, management must be enabled using enable_management().