Esempio n. 1
0
def send_message():


    queue = Queue()
    queue.connect(connection_params)
    body = json.dumps({"Body":"Test"})
    queue.send(exchange_name, "test.send", body, exchange_type="topic")
Esempio n. 2
0
class QueueTest(unittest.TestCase):

    def setUp(self):
        self._queue = Queue()
        self._queue.connection = mock.Mock(BlockingConnection)
        self._queue.channel = mock.Mock(BlockingChannel)

    def test_declare_queue(self):

        queue_options = {"auto_delete":True}

        queue_name_1 = "testa"
        queue_name_2 = "testb"
        queue_name_3 = "testc"


        queue_name = self._queue.declare_queue(queue_name_1, queue_options)
        self._queue.channel.queue_declare.assert_called_once_with(queue=queue_name_1, **queue_options)

        print queue_name

        self.assertEqual(1, len(self._queue.declared_channels))

        queue_name = self._queue.declare_queue(queue_name_1, queue_options)
        self._queue.channel.queue_declare.assert_called_once_with(queue=queue_name_1, **queue_options)

        print queue_name

        self.assertEqual(1, len(self._queue.declared_channels))

        self._queue.declare_queue(queue_name_2, queue_options)
        self._queue.channel.queue_declare.assert_called_with(queue=queue_name_2, **queue_options)

        self.assertEqual(2, len(self._queue.declared_channels))

    def test_send(self):

        queue_options = {"auto_delete":True}
        queue_name = "testa"
        exchange = "test-ex"
        routing_key = "test-rk"
        body = "TestBody"

        self._queue.send(exchange, routing_key, body)
        self._queue.channel.basic_publish.assert_called_once_with(body=body, exchange='test-ex', routing_key='test-rk', properties=ANY)