How to use the kombu.Producer function in kombu

To help you get started, we’ve selected a few kombu 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 celery / kombu / async_test_queue_declare.py View on Github external
def send_messages(connection):
    producer = Producer(connection, auto_declare=False)
    return barrier([
        producer.publish({'hello': i},
                         exchange=TEST_QUEUE.exchange,
                         routing_key=TEST_QUEUE.routing_key,
                         declare=[TEST_QUEUE],
                         callback=on_message_written)
        for i in range(N)
    ])
github celery / kombu / t / unit / transport / test_redis.py View on Github external
def test_publish__get_redispyv2(self):
        channel = self.connection.channel()
        producer = Producer(channel, self.exchange, routing_key='test_Redis')
        self.queue(channel).declare()

        producer.publish({'hello': 'world'})

        assert self.queue(channel).get().payload == {'hello': 'world'}
        assert self.queue(channel).get() is None
        assert self.queue(channel).get() is None
        assert self.queue(channel).get() is None
github gwu-libraries / sfm-weibo-harvester / tests / test_weibo_harvester.py View on Github external
"path": self.path,
            "credentials": {
                "access_token": tests.WEIBO_ACCESS_TOKEN
            },
            "collection_set": {
                "id": "test_collection_set"
            },
            "collection": {
                "id": "test_collection"
            },
            "options": {
            }
        }
        with self._create_connection() as connection:
            bound_exchange = self.exchange(connection)
            producer = Producer(connection, exchange=bound_exchange)
            producer.publish(harvest_msg, routing_key="harvest.start.weibo.weibo_timeline")

            # Now wait for status message.
            status_msg = self._wait_for_message(self.result_queue, connection)
            # Matching ids
            self.assertEqual("test:3", status_msg["id"])
            # Running
            self.assertEqual(STATUS_RUNNING, status_msg["status"])

            # Another running message
            status_msg = self._wait_for_message(self.result_queue, connection)
            self.assertEqual(STATUS_RUNNING, status_msg["status"])

            # Now wait for result message.
            result_msg = self._wait_for_message(self.result_queue, connection)
            # Matching ids
github celery / kombu / t / unit / test_messaging.py View on Github external
def test_no_channel(self):
        p = Producer(None)
        assert not p._channel
github RackHD / RackHD / test / stream-monitor / stream_sources / amqp_source.py View on Github external
def inject(self, exchange, routing_key, payload):
        self.__logs.irl.debug("Injecting a test AMQP message: ex=%s, rk=%s, payload=%s", exchange, routing_key, payload)
        if not isinstance(exchange, Exchange):
            exchange = Exchange(exchange, 'topic')
        prod = Producer(self.__connection, exchange=exchange, routing_key=routing_key)
        prod.publish(payload)
github celery / kombu / t / unit / test_messaging.py View on Github external
def test_on_return(self):
        chan = self.connection.channel()

        def on_return(exception, exchange, routing_key, message):
            pass

        p = Producer(chan, on_return=on_return)
        assert on_return in chan.events['basic_return']
        assert p.on_return
github FORTH-ICS-INSPIRE / artemis / monitor / core / taps / exabgp_client.py View on Github external
"timestamp": float(bgp_message["timestamp"]),
                        "path": bgp_message.get("path", []),
                        "service": "exabgp|{}".format(self.host),
                        "prefix": bgp_message["prefix"],
                        "peer_asn": int(bgp_message["peer_asn"]),
                    }
                    for prefix in self.prefixes:
                        try:
                            base_ip, mask_length = bgp_message["prefix"].split("/")
                            our_prefix = IPNetwork(prefix)
                            if (
                                IPAddress(base_ip) in our_prefix
                                and int(mask_length) >= our_prefix.prefixlen
                            ):
                                if validator.validate(msg):
                                    with Producer(connection) as producer:
                                        msgs = normalize_msg_path(msg)
                                        for msg in msgs:
                                            key_generator(msg)
                                            log.debug(msg)
                                            if self.autoconf:
                                                if str(our_prefix) in [
                                                    "0.0.0.0/0",
                                                    "::/0",
                                                ]:
                                                    if msg["type"] == "A":
                                                        as_path = clean_as_path(
                                                            msg["path"]
                                                        )
                                                        if len(as_path) > 1:
                                                            # ignore, since this is not a self-network origination, but sth transit
                                                            break
github celery / celery / celery / events / dispatcher.py View on Github external
def enable(self):
        self.producer = Producer(self.channel or self.connection,
                                 exchange=self.exchange,
                                 serializer=self.serializer,
                                 auto_declare=False)
        self.enabled = True
        for callback in self.on_enabled:
            callback()
github alerta / alerta-contrib / plugins / amqp / alerta_amqp.py View on Github external
def __init__(self, name=None):
        if app.config['DEBUG']:
            setup_logging(loglevel='DEBUG', loggers=[''])

        self.connection = BrokerConnection(AMQP_URL)
        try:
            self.connection.connect()
        except Exception as e:
            LOG.error('Failed to connect to AMQP transport %s: %s', AMQP_URL, e)
            raise RuntimeError

        self.channel = self.connection.channel()
        self.exchange_name = AMQP_TOPIC

        self.exchange = Exchange(name=self.exchange_name, type='fanout', channel=self.channel)
        self.producer = Producer(exchange=self.exchange, channel=self.channel)

        super(FanoutPublisher, self).__init__(name)

        LOG.info('Configured fanout publisher on topic "%s"', AMQP_TOPIC)
github ansible / awx / awx / main / dispatch / publish.py View on Github external
getattr(cls.queue, 'im_func', cls.queue) or
                    settings.CELERY_DEFAULT_QUEUE
                )
                obj = {
                    'uuid': task_id,
                    'args': args,
                    'kwargs': kwargs,
                    'task': cls.name
                }
                obj.update(**kw)
                if callable(queue):
                    queue = queue()
                if not settings.IS_TESTING(sys.argv):
                    with Connection(settings.BROKER_URL) as conn:
                        exchange = Exchange(queue, type=exchange_type or 'direct')
                        producer = Producer(conn)
                        logger.debug('publish {}({}, queue={})'.format(
                            cls.name,
                            task_id,
                            queue
                        ))
                        producer.publish(obj,
                                         serializer='json',
                                         compression='bzip2',
                                         exchange=exchange,
                                         declare=[exchange],
                                         delivery_mode="persistent",
                                         routing_key=queue)
                return (obj, queue)