How to use the amqp.exceptions.PreconditionFailed function in amqp

To help you get started, we’ve selected a few amqp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cenkalti / kuyruk / tests / integration / test_worker.py View on Github external
def test_declare_error(self):
        """Worker failed to start if existing queue arguments are different"""
        with tasks.kuyruk.channel() as ch:
            ch.queue_declare("kuyruk", durable=False)
        self.assertRaises(amqp.exceptions.PreconditionFailed,
                          tasks.echo,
                          args=('hello world', ))
        with run_worker(terminate=False) as worker:
            worker.expect('PRECONDITION_FAILED')
github nameko / nameko / test / amqp / test_publish.py View on Github external
def test_user_id(
        self, publisher, get_message_from_queue, queue, rabbit_config
    ):
        user_id = rabbit_config['username']

        # successful case
        publisher.publish("payload", user_id=user_id)

        message = get_message_from_queue(queue.name)
        assert message.properties['user_id'] == user_id

        # when user_id does not match the current user, expect an error
        with pytest.raises(PreconditionFailed):
            publisher.publish("payload", user_id="invalid")
github binux / pyspider / pyspider / message_queue / rabbitmq.py View on Github external
def reconnect(self):
        """Reconnect to rabbitmq server"""
        parsed = urlparse.urlparse(self.amqp_url)
        port = parsed.port or 5672
        self.connection = amqp.Connection(host="%s:%s" % (parsed.hostname, port),
                                          userid=parsed.username or 'guest',
                                          password=parsed.password or 'guest',
                                          virtual_host=unquote(
                                              parsed.path.lstrip('/') or '%2F'))
        self.channel = self.connection.channel()
        try:
            self.channel.queue_declare(self.name)
        except amqp.exceptions.PreconditionFailed:
            pass
        #self.channel.queue_purge(self.name)
github pangyemeng / myjob / pyspider / pyspider_es / pyspider / message_queue / rabbitmq.py View on Github external
def reconnect(self):
        """Reconnect to rabbitmq server"""
        parsed = urlparse.urlparse(self.amqp_url)
        port = parsed.port or 5672
        self.connection = amqp.Connection(host="%s:%s" % (parsed.hostname, port),
                                          userid=parsed.username or 'guest',
                                          password=parsed.password or 'guest',
                                          virtual_host=unquote(
                                              parsed.path.lstrip('/') or '%2F'))
        self.channel = self.connection.channel()
        try:
            self.channel.queue_declare(self.name)
        except amqp.exceptions.PreconditionFailed:
            pass
        #self.channel.queue_purge(self.name)