Esempio n. 1
0
 def _maybe_subscribe(self, subscription):
     """ May be subscribe to queue. """
     if "queue" in subscription:
         queue_name = self._maybe_declare_queue(subscription["queue"])
     else:
         raise AmqpcltError("subscription must contain a queue")
     exchange_name = None
     if "exchange" in subscription:
         exchange_name = self._maybe_declare_exchange(
             subscription["exchange"])
     if exchange_name:
         self._maybe_bind(queue_name, exchange_name,
                          subscription.get("routing_key", ""))
     if queue_name not in self._consume:
         LOGGER.debug("incoming consume from queue: %s" % (queue_name, ))
         tag = get_uuid()
         params = {
             "consumer_callback": self._handle_delivery,
             "queue": queue_name,
             "consumer_tag": tag
         }
         if not self._config["reliable"]:
             params["no_ack"] = True
         self._channel.basic_consume(**params)
         self._consume[queue_name] = tag
Esempio n. 2
0
 def _maybe_subscribe(self, subscription):
     """ May be subscribe to queue. """
     if "queue" in subscription:
         queue_name = self._maybe_declare_queue(subscription["queue"])
     else:
         raise AmqpcltError("subscription must contain a queue")
     exchange_name = None
     if "exchange" in subscription:
         exchange_name = self._maybe_declare_exchange(
             subscription["exchange"])
     if exchange_name:
         self._maybe_bind(queue_name,
                          exchange_name,
                          subscription.get("routing_key", ""))
     if queue_name not in self._consume:
         LOGGER.debug("incoming consume from queue: %s" % (queue_name, ))
         tag = get_uuid()
         params = {"callback": self._handle_message,
                   "no_ack": False,
                   "queue": queue_name,
                   "consumer_tag": tag}
         if not self._config["reliable"]:
             params["no_ack"] = True
         self._channel.basic_consume(**params)
         self._consume[queue_name] = tag
Esempio n. 3
0
 def _maybe_declare_queue(self, queue_props):
     """ May be declare a queue. """
     queue_name = queue_props.get("name", "")
     if queue_name and queue_name in self._queue:
         return queue_name
     if not queue_name:
         queue_name = get_uuid()
     self._channel.queue_declare(
         queue=queue_name,
         durable=queue_props.get("durable", False),
         exclusive=queue_props.get("exclusive", False),
         auto_delete=queue_props.get("auto_delete", False),
         arguments=queue_props.get("arguments", dict()))
     #        if not queue_name:
     #            # amq generated queue
     #            queue_name = result.method.queue
     LOGGER.debug("incoming queue declared: %s" % (queue_name, ))
     self._queue[queue_name] = 1
     return queue_name
Esempio n. 4
0
    def _maybe_declare_queue(self, queue_props):
        """ May be declare a queue. """
        queue_name = queue_props.get("name", "")
        if queue_name and queue_name in self._queue:
            return queue_name
        if not queue_name:
            queue_name = get_uuid()
        self._channel.queue_declare(
            queue=queue_name,
            durable=queue_props.get("durable", False),
            exclusive=queue_props.get("exclusive", False),
            auto_delete=queue_props.get("auto_delete", False),
            arguments=queue_props.get("arguments", dict()))
#        if not queue_name:
#            # amq generated queue
#            queue_name = result.method.queue
        LOGGER.debug("incoming queue declared: %s" % (queue_name, ))
        self._queue[queue_name] = 1
        return queue_name
Esempio n. 5
0
 def test_get_uuid(self):
     """ Test get_uuid function. """
     self.assert_(type(get_uuid()) == str)