Initial commit.
[patchq.git] / create-queues.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Create all the exchanges, queues and other objects in RabbitMQ.
5 #
6 # You must configure the hostname of the RabbitMQ server in
7 # ‘config.py’ first.
8 #
9 # You only have to run this once, but you must run it before running
10 # any other part of patchq.
11 #
12 # All RabbitMQ objects created are prefixed by ‘patchq_...’.  To
13 # reverse the effects of this script, delete those objects (using
14 # rabbitmqadmin or similar).
15
16 import pika
17 import config
18
19 connection = pika.BlockingConnection(pika.ConnectionParameters(
20     host = config.mq_server))
21 channel = connection.channel()
22
23 # Create the input exchange and queue which take raw emails in any
24 # order and queues them so they can be later threaded and ordered (by
25 # ‘threader.py’).
26 channel.exchange_declare(exchange = 'patchq_input',
27                          exchange_type = 'fanout',
28                          durable = True)
29 q = channel.queue_declare(queue = 'patchq_input',
30                           durable = True)
31 channel.queue_bind(exchange = 'patchq_input',
32                    queue = q.method.queue)
33
34 # Create the exchange and queue(s) which take fully threaded and
35 # ordered patch series and passes them to the tests.
36 channel.exchange_declare (exchange = 'patchq_thread',
37                           exchange_type = 'fanout',
38                           durable = True)
39 for t in config.tests:
40     qname = "patchq_test_%s" % t
41     q = channel.queue_declare(queue = qname,
42                               durable = True)
43     channel.queue_bind(exchange = 'patchq_thread',
44                        queue = q.method.queue)
45
46 # Create the email results queue.
47 channel.exchange_declare(exchange = 'patchq_reports',
48                          exchange_type = 'fanout',
49                          durable = True)
50 q = channel.queue_declare(queue = 'patchq_reports',
51                           durable = True)
52 channel.queue_bind(exchange = 'patchq_reports',
53                    queue = q.method.queue)
54
55 print "All done."
56 print
57 print "You might want to look at the queues and exchanges by running"
58 print "‘rabbitmqctl list_queues’ and ‘rabbitmqctl list_exchanges’."
59 print
60 print "If you want to see the queue contents in more detail, then use"
61 print "rabbitmqadmin, see:"
62 print "  https://www.rabbitmq.com/management-cli.html"
63 print "  https://stackoverflow.com/questions/10709533/is-it-possible-to-view-rabbitmq-message-contents-directly-from-the-command-line"