Rabbit MQ Helpers¶
-
class
test_helpers.rabbit.RabbitMqFixture(host, user, password)¶ Manages a Rabbit MQ virtual host.
Create an instance of this class when you need to programmatically manage a Rabbit MQ cluster. Pika gives you the ability to create exchanges and queues and bind them together using the AMQP protocol but there is no way to create a new virtual host. Despite that, running tests on randomly unique virtual hosts is quite convenient.
This class uses Rabbit’s HTTP API to manipulate the cluster. It exposes the management functions that have proven useful for writing tests against a shared RabbitMQ cluster.
Usage Example
from test_helpers import rabbit _fixture = rabbit.RabbitMqFixture('localhost', 'guest', 'guest') def setup_module(): _fixture.install_virtual_host() _fixture.create_binding('accounts', 'my_queue', 'status.added') # from this point on, os.environ['AMQP'] points to a # newly created, isolated virtual host that will be # removed when the test is complete
-
create_binding(exchange_name, queue_name, routing_key)¶ Create a message binding.
Parameters: This method creates the specified queue and exchange if they do not already exist and then binds routing_key such that messages with it are routed through the exchange and queue.
-
host¶ The URL-quoted rabbit server.
-
install_virtual_host()¶ Create a new virtual host.
Returns: the name of the virtual host The virtual host will be created and the current user will be granted full permission to it.
This method also sets the
AMQPenvironment variable to the appropriate URL for connecting to the virtual host.
-
password¶ The URL-quoted rabbit password.
-
purge_queue(queue_name)¶ Purge a Rabbit MQ queue.
-
remove_virtual_host()¶ Remove the generated virtual host.
-
user¶ The URL-quoted rabbit user name.
-
virtual_host¶ The URL-quoted virtual host ready to use as-is.
-