Example #1
0
 def reject(self, delivery_tag, requeue=False):
     """
     Rejects a message using the delivery tag.
     Should be called by the EP layer.
     """
     log.debug("RecvChannel.reject: %s", delivery_tag)
     self._ensure_amq_chan()
     blocking_cb(self._amq_chan.basic_reject, 'callback', delivery_tag, requeue=requeue)
Example #2
0
    def _destroy_queue(self):
        """
        You should only call this if you want to delete the queue. Even so, you must know you are
        the only one on it - there appears to be no mechanic for determining if anyone else is listening.
        """
        assert self._recv_name and isinstance(self._recv_name, tuple) and self._recv_name[1]

        self._ensure_amq_chan()

        log.info("Destroying listener for queue %s", self._recv_name)
        blocking_cb(self._amq_chan.queue_delete, 'callback', queue=self._recv_name[1])
Example #3
0
    def _destroy_binding(self):
        """
        Deletes the binding from the listening queue.
        """
        assert self._recv_name and isinstance(self._recv_name, tuple) and self._recv_name[1] and self._recv_binding

        self._ensure_amq_chan()

        blocking_cb(self._amq_chan.queue_unbind, 'callback', queue=self._recv_name[1],
                                                             exchange=self._recv_name[0],
                                                             routing_key=self._recv_binding)
Example #4
0
    def _bind(self, binding):
        log.debug("RecvChannel._bind: %s", binding)
        assert self._recv_name and self._recv_name[1]

        self._ensure_amq_chan()
        
        queue = self._recv_name[1]
        blocking_cb(self._amq_chan.queue_bind, 'callback',
                    queue=queue,
                    exchange=self._recv_name[0],
                    routing_key=binding)

        self._recv_binding = binding
Example #5
0
    def _new_transport(self, ch_number=None):
        """
        Creates a new AMQPTransport with an underlying Pika channel.
        """
        amq_chan = blocking_cb(self.client.channel,
                               'on_open_callback',
                               channel_number=ch_number)
        if amq_chan is None:
            log.error(
                "AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s",
                ch_number)
            from pyon.container.cc import Container
            if Container.instance is not None:
                Container.instance.fail_fast(
                    "AMQCHAN IS NONE, messaging has failed", True)
            raise StandardError(
                "AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s"
                % ch_number)

        transport = AMQPTransport(amq_chan)

        # return the pending in collection (lets this number be assigned again later)
        self.client._pending.remove(transport.channel_number)

        # by default, everything should have a prefetch count of 1 (configurable)
        # this can be overridden by the channel get_n related methods
        transport.qos_impl(prefetch_count=CFG.get_safe(
            'container.messaging.endpoint.prefetch_count', 1))

        return transport
Example #6
0
 def _new_channel(self, ch_type, ch_number=None, **kwargs):
     """
     Creates a pyon Channel based on the passed in type, and activates it for use.
     """
     chan = ch_type(**kwargs)
     amq_chan = blocking_cb(self.client.channel, 'on_open_callback', channel_number=ch_number)
     chan.on_channel_open(amq_chan)
     return chan
Example #7
0
    def stop_consume(self):
        """
        Stops consuming messages.

        If the queue has auto_delete, this will delete it.
        """
        log.debug("RecvChannel.stop_consume")
        if not self._consuming:
            raise ChannelError("Not consuming")

        if self._queue_auto_delete:
            log.debug("Autodelete is on, this will destroy this queue: %s", self._recv_name[1])

        self._ensure_amq_chan()

        blocking_cb(self._amq_chan.basic_cancel, 'callback', self._consumer_tag)
        self._consuming = False
Example #8
0
 def _new_channel(self, ch_type, ch_number=None, **kwargs):
     """
     Creates a pyon Channel based on the passed in type, and activates it for use.
     """
     chan = ch_type(**kwargs)
     amq_chan = blocking_cb(self.client.channel,
                            'on_open_callback',
                            channel_number=ch_number)
     chan.on_channel_open(amq_chan)
     return chan
Example #9
0
    def _get_channel(self, node):
        """
        Get a raw channel to be used by all the ensure_exists methods.
        """
        assert self.container

        # @TODO: needs lock, but so do all these methods
        if not self._chan:
            self._chan = blocking_cb(node.client.channel, 'on_open_callback')

        return self._chan
Example #10
0
    def _declare_exchange_point(self, xp):
        """
        Performs an AMQP exchange declare.

        @param  xp      The name of the exchange to use.
        @TODO: this really shouldn't exist, messaging layer should not make this declaration.  it will be provided.
               perhaps push into an ion layer derivation to help bootstrapping / getting started fast.
        """
        self._exchange = xp
        assert self._exchange

        self._ensure_amq_chan()

        # EXCHANGE INTERACTION HERE - use async method to wait for it to finish
        log.debug("Exchange declare: %s, TYPE %s, DUR %s AD %s", self._exchange, self._exchange_type,
                                                                 self._exchange_durable, self._exchange_auto_delete)
        blocking_cb(self._amq_chan.exchange_declare, 'callback', exchange=self._exchange,
                                                                type=self._exchange_type,
                                                                durable=self._exchange_durable,
                                                                auto_delete=self._exchange_auto_delete)
Example #11
0
    def _get_channel(self, node):
        """
        Get a raw channel to be used by all the ensure_exists methods.
        """
        assert self.container

        # @TODO: needs lock, but so do all these methods
        if not self._chan:
            self._chan = blocking_cb(node.client.channel, 'on_open_callback')

        return self._chan
Example #12
0
    def _new_transport(self, ch_number=None):
        """
        Creates a new AMQPTransport with an underlying Pika channel.
        """
        amq_chan = blocking_cb(self.client.channel, 'on_open_callback', channel_number=ch_number)
        if amq_chan is None:
            log.error("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s", ch_number)
            import traceback
            traceback.print_stack()
            raise StandardError("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s" % ch_number)

        transport = AMQPTransport(amq_chan)
        return transport
Example #13
0
    def _new_channel(self, ch_type, ch_number=None, **kwargs):
        """
        Creates a pyon Channel based on the passed in type, and activates it for use.
        """
        chan = ch_type(**kwargs)
        amq_chan = blocking_cb(self.client.channel, 'on_open_callback', channel_number=ch_number)
        if amq_chan is None:
            log.error("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s", ch_number)
            import traceback
            traceback.print_stack()
            raise StandardError("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s" % ch_number)

        chan.on_channel_open(amq_chan)
        return chan
Example #14
0
    def _get_channel(self, node):
        """
        Get a raw channel to be used by all the ensure_exists methods.
        """
        assert self.container

        # @TODO: needs lock, but so do all these methods
        if not self._chan or (self._chan and self._chan.closing is not None):

            # if you want to play with node internals, you have to play nice with the node.. needs the lock!
            with node._lock:
                self._chan = blocking_cb(node.client.channel, 'on_open_callback')

        return self._chan
Example #15
0
    def _new_transport(self, ch_number=None):
        """
        Creates a new AMQPTransport with an underlying Pika channel.
        """
        amq_chan = blocking_cb(self.client.channel, 'on_open_callback', channel_number=ch_number)
        if amq_chan is None:
            log.error("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s", ch_number)
            traceback.print_stack()
            from pyon.container.cc import Container
            if Container.instance is not None:
                Container.instance.fail_fast("AMQCHAN IS NONE, messaging has failed", True)
            raise StandardError("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s" % ch_number)

        transport = AMQPTransport(amq_chan)
        return transport
Example #16
0
    def _new_transport(self, ch_number=None):
        """
        Creates a new AMQPTransport with an underlying Pika channel.
        """
        amq_chan = blocking_cb(self.client.channel, 'on_open_callback', channel_number=ch_number)
        if amq_chan is None:
            log.error("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s", ch_number)
            from pyon.container.cc import Container
            if Container.instance is not None:
                Container.instance.fail_fast("AMQCHAN IS NONE, messaging has failed", True)
            raise StandardError("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s" % ch_number)

        transport = AMQPTransport(amq_chan)

        # by default, everything should have a prefetch count of 1 (configurable)
        # this can be overridden by the channel get_n related methods
        transport.qos_impl(prefetch_count=CFG.get_safe('container.messaging.endpoint.prefetch_count', 1))

        return transport
Example #17
0
    def _new_channel(self, ch_type, ch_number=None, **kwargs):
        """
        Creates a pyon Channel based on the passed in type, and activates it for use.
        """
        chan = ch_type(**kwargs)
        amq_chan = blocking_cb(self.client.channel,
                               'on_open_callback',
                               channel_number=ch_number)
        if amq_chan is None:
            log.error(
                "AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s",
                ch_number)
            import traceback
            traceback.print_stack()
            raise StandardError(
                "AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s"
                % ch_number)

        chan.on_channel_open(amq_chan)
        return chan
Example #18
0
    def _declare_queue(self, queue):

        # prepend xp name in the queue for anti-clobbering
        if queue:
            log.debug('Auto-prepending sysname to queue name for anti-clobbering')
            queue = ".".join([self._recv_name[0], queue])

        self._ensure_amq_chan()

        log.debug("RecvChannel._declare_queue: %s", queue)
        frame = blocking_cb(self._amq_chan.queue_declare, 'callback',
                            queue=queue or '',
                            auto_delete=self._queue_auto_delete,
                            durable=self._queue_durable)

        # if the queue was anon, save it
        #if queue is None:
        # always save the new recv_name - we may have created a new one
        self._recv_name = (self._recv_name[0], frame.method.queue)

        return self._recv_name[1]
Example #19
0
 def test_blocking(self):
     a, b, c, misc = blocking_cb(self.i_call_callbacks, cb_arg='cb')
     self.assertEqual((a, b, c, misc), (1, 2, 3, {'foo': 'bar'}))
Example #20
0
 def test_blocking(self):
     a, b, c, misc = blocking_cb(self.i_call_callbacks, cb_arg="cb")
     self.assertEqual((a, b, c, misc), (1, 2, 3, {"foo": "bar"}))
Example #21
0
 def test_blocking(self):
     a, b, c, misc = blocking_cb(self.i_call_callbacks, cb_arg='cb')
     self.assertEqual((a, b, c, misc), (1, 2, 3, {'foo': 'bar'}))