def setUp(self):
     super(ConsumerPropertyTests, self).setUp()
     self.config = {'foo': 'bar', 'baz': 1, 'qux': True}
     self.message = data.Message(mocks.CHANNEL, mocks.METHOD,
                                 mocks.PROPERTIES, mocks.BODY)
     self.obj = TestConsumer(self.config, None)
     yield self.obj._execute(self.message)
Exemple #2
0
    def on_delivery(self, name, channel, method, properties, body):
        """Process a message from Rabbit

        :param str name: The connection name
        :param pika.channel.Channel channel: The message's delivery channel
        :param pika.frames.MethodFrame method: The method frame
        :param pika.spec.BasicProperties properties: The message properties
        :param str body: The message body

        """
        message = data.Message(name, channel, method, properties, body)
        if self.is_processing:
            return self.pending.append(message)
        self.invoke_consumer(message)
Exemple #3
0
    def process(self, channel=None, method=None, properties=None, body=None):
        """Process a message from Rabbit

        :param pika.channel.Channel channel: The channel the message was sent on
        :param pika.frames.MethodFrame method: The method frame
        :param pika.spec.BasicProperties properties: The message properties
        :param str body: The message body

        """
        if not self.is_idle:
            LOGGER.critical('Received a message while in state: %s',
                            self.state_description)
            return self.reject(method.delivery_tag, True)
        self.set_state(self.STATE_PROCESSING)
        message = data.Message(channel, method, properties, body)
        if method.redelivered:
            self.stats.incr(self.REDELIVERED)
        self.invoke_consumer(method, message)
Exemple #4
0
    def on_message(self,
                   channel=None,
                   method=None,
                   properties=None,
                   body=None):
        """Process a message from Rabbit

        :param pika.channel.Channel channel: The channel the message was sent on
        :param pika.frames.MethodFrame method: The method frame
        :param pika.spec.BasicProperties properties: The message properties
        :param str body: The message body

        """
        if method.redelivered:
            self.stats.incr(self.REDELIVERED)
        try:
            self.invoke_consumer(
                data.Message(channel, method, properties, body))
        except AttributeError:
            pass
Exemple #5
0
    def create_message(self, message, properties=None,
                       exchange='rejected', routing_key='test'):
        """Create a message instance for use with the consumer in testing.

        :param any message: the body of the message to create
        :param dict properties: AMQP message properties
        :param str exchange: The exchange the message should appear to be from
        :param str routing_key: The message's routing key
        :rtype: :class:`rejected.data.Message`

        """
        if not properties:
            properties = {}
        if isinstance(message, dict) and \
                properties.get('content_type') == 'application/json':
            message = json.dumps(message)
        return data.Message(
            connection='mock',
            channel=self.process.connections['mock'].channel,
            method=spec.Basic.Deliver(
                'ctag0', 1, False, exchange, routing_key),
            properties=spec.BasicProperties(
                app_id=properties.get('app_id', 'rejected.testing'),
                content_encoding=properties.get('content_encoding'),
                content_type=properties.get('content_type'),
                correlation_id=properties.get(
                    'correlation_id', self.correlation_id),
                delivery_mode=properties.get('delivery_mode', 1),
                expiration=properties.get('expiration'),
                headers=properties.get('headers'),
                message_id=properties.get('message_id', str(uuid.uuid4())),
                priority=properties.get('priority'),
                reply_to=properties.get('reply_to'),
                timestamp=properties.get('timestamp', int(time.time())),
                type=properties.get('type'),
                user_id=properties.get('user_id')
            ), body=message)
Exemple #6
0
 def setUp(self):
     self._obj = data.Message(mocks.CHANNEL,
                              mocks.METHOD,
                              mocks.PROPERTIES,
                              mocks.BODY)
Exemple #7
0
 def setUp(self):
     self.message = data.Message('mock', mocks.CHANNEL, mocks.METHOD,
                                 mocks.PROPERTIES, mocks.BODY)
 def setUp(self):
     super(ConsumerReceiveTests, self).setUp()
     self.obj = TestConsumer({}, None)
     self.message = data.Message(mocks.CHANNEL, mocks.METHOD,
                                 mocks.PROPERTIES, mocks.BODY)
 def setUp(self):
     self.body = {'foo': 'bar', 'baz': 1, 'qux': True}
     self.message = data.Message(mocks.CHANNEL, mocks.METHOD,
                                 mocks.PROPERTIES, json.dumps(self.body))
     self.obj = TestSmartConsumer({}, None)
     self.obj._execute(self.message)
Exemple #10
0
 def setUp(self):
     self.obj = TestConsumer({})
     self.message = data.Message(mocks.CHANNEL, mocks.METHOD,
                                 mocks.PROPERTIES, mocks.BODY)