Exemple #1
0
 def setUp(self):
     super(WriteFrameTests, self).setUp()
     self.queue = amqp_queue.Queue(self.channel, self.NAME, self.DURABLE,
                                   self.EXCLUSIVE, self.AUTO_DELETE,
                                   self.MAX_LENGTH, self.MESSAGE_TTL,
                                   self.EXPIRES, self.DEAD_LETTER_EXCHANGE,
                                   self.DEAD_LETTER_ROUTING_KEY)
Exemple #2
0
 def test_default_declare_passive(self):
     obj = amqp_queue.Queue(self.chan)
     expectation = {
         'arguments': {},
         'auto_delete': False,
         'durable': False,
         'exclusive': False,
         'nowait': False,
         'passive': True,
         'queue': '',
         'ticket': 0
     }
     self.assertDictEqual(dict(obj._declare(True)), expectation)
Exemple #3
0
def create_queue(uri=None,
                 queue_name='',
                 durable=True,
                 auto_delete=False,
                 max_length=None,
                 message_ttl=None,
                 expires=None,
                 dead_letter_exchange=None,
                 dead_letter_routing_key=None,
                 arguments=None):
    """Create a queue with RabbitMQ. This should only be used for one-off
    operations. If a queue name is omitted, the name will be automatically
    generated by RabbitMQ.

    :param str uri: AMQP URI to connect to
    :param str queue_name: The queue name to create
    :param durable: Indicates if the queue should survive a RabbitMQ is restart
    :type durable: bool
    :param bool auto_delete: Automatically delete when all consumers disconnect
    :param int max_length: Maximum queue length
    :param int message_ttl: Time-to-live of a message in milliseconds
    :param expires: Milliseconds until a queue is removed after becoming idle
    :type expires: int
    :param dead_letter_exchange: Dead letter exchange for rejected messages
    :type dead_letter_exchange: str
    :param dead_letter_routing_key: Routing key for dead lettered messages
    :type dead_letter_routing_key: str
    :param dict arguments: Custom arguments for the queue
    :raises: :py:class:`ValueError`
    :raises: :py:class:`rabbitpy.RemoteClosedException`

    """
    dlx_routing_key = dead_letter_routing_key
    with connection.Connection(uri) as conn:
        with conn.channel() as channel:
            obj = amqp_queue.Queue(channel,
                                   queue_name,
                                   durable=durable,
                                   auto_delete=auto_delete,
                                   max_length=max_length,
                                   message_ttl=message_ttl,
                                   expires=expires,
                                   dead_letter_exchange=dead_letter_exchange,
                                   dead_letter_routing_key=dlx_routing_key,
                                   arguments=arguments)
            obj.declare()
Exemple #4
0
 def test_stop_consuming_raises_exception(self):
     queue = amqp_queue.Queue(self.chan)
     self.assertRaises(exceptions.NotConsumingError, queue.stop_consuming)
Exemple #5
0
 def test_dlr_unicode(self):
     routing_key = unicode('routing-key')
     queue = amqp_queue.Queue(self.chan,
                              dead_letter_routing_key=routing_key)
     self.assertIsInstance(queue.dead_letter_routing_key, unicode)
Exemple #6
0
 def test_dlr_str(self):
     queue = amqp_queue.Queue(self.chan,
                              dead_letter_routing_key='routing-key')
     self.assertIsInstance(queue.dead_letter_routing_key, str)