How to use the amqp.Message 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 mozilla / fjord / vendor / packages / amqp / demo / demo_send.py View on Github external
options, args = parser.parse_args()

    if not args:
        parser.print_help()
        sys.exit(1)

    msg_body = ' '.join(args)

    conn = amqp.Connection(options.host, userid=options.userid,
                           password=options.password, ssl=options.ssl)

    ch = conn.channel()
    ch.exchange_declare('myfan', 'fanout')

    msg = amqp.Message(msg_body, content_type='text/plain',
                       application_headers={'foo': 7, 'bar': 'baz'})

    ch.basic_publish(msg, 'myfan')

    ch.close()
    conn.close()
github MetPX / sarracenia / sarra / sr_amqp.py View on Github external
ebo=2
      connected=True
      while True:
        if 'v03.' in exchange_key:
            ct='application/json'
        else:
            ct='text/plain'
        try:
            if self.hc.use_amqp:
                self.logger.debug("publish AMQP is used")
                if mexp:
                    expms = '%s' % mexp
                    msg = amqp.Message(message, content_type=ct, application_headers=mheaders,
                                       expiration=expms)
                else:
                    msg = amqp.Message(message, content_type=ct, application_headers=mheaders)
                self.channel.basic_publish(msg, exchange_name, exchange_key)
                self.channel.tx_commit()
            elif self.hc.use_amqplib:
                self.logger.debug("publish AMQPLIB is used")
                if mexp:
                    expms = '%s' % mexp
                    msg = amqplib_0_8.Message(message, content_type=ct, application_headers=mheaders,
                                              expiration=expms)
                else:
                    msg = amqplib_0_8.Message(message, content_type=ct, application_headers=mheaders)
                self.channel.basic_publish(msg, exchange_name, exchange_key)
                self.channel.tx_commit()
            elif self.hc.use_pika:
                self.logger.debug("publish PIKA is used")
                if mexp:
                    expms = '%s' % mexp
github jortel / gofer / src / gofer / messaging / adapter / amqp / producer.py View on Github external
:type durable: bool
    :return: The message.
    :rtype: Message
    """
    properties = {}

    if ttl:
        ms = ttl * 1000  # milliseconds
        properties.update(expiration=str(ms))

    if durable:
        properties.update(delivery_mode=2)
    else:
        properties.update(delivery_mode=1)

    return Message(body, **properties)
github galaxyproject / galaxy / scripts / galaxy_messaging / client / amqp_publisher.py View on Github external
def handle_scan(states, amqp_config, barcode):
    if states.get(barcode[:2], None):
        values = dict( BARCODE=barcode[2:],
                       STATE=states.get(barcode[:2]),
                       API_KEY=amqp_config['api_key'] )
        print values
        data = xml % values
        print data
        conn = amqp.Connection(host=amqp_config['host']+":"+amqp_config['port'],
                               userid=amqp_config['userid'],
                               password=amqp_config['password'],
                               virtual_host=amqp_config['virtual_host'],)

        chan = conn.channel()
        msg = amqp.Message(data,
                           content_type='text/plain',
                           application_headers={'msg_type': 'sample_state_update'})
        msg.properties["delivery_mode"] = 2
        chan.basic_publish(msg,
                           exchange=amqp_config['exchange'],
                           routing_key=amqp_config['routing_key'])
        chan.close()
        conn.close()
github augerai / a2ml / a2ml / tasks_queue / tasks_hub_api.py View on Github external
o = urlparse(task_config.broker_url)

    connection_params = {
        'host': o.hostname,
        'port': o.port,
        'userid': o.username,
        'password': o.password,
        'virtual_host': o.path.replace('/', '')
    }

    with amqp.Connection(**connection_params) as c:
        channel = c.channel()
        channel.queue_declare(task_config.task_result_queue, durable=True, auto_delete=False)

        channel.basic_publish(
            amqp.Message(json_data, delivery_mode=PERSISTENT_DELIVERY_MODE),
            routing_key=task_config.task_result_queue
        )
github taigaio / taiga-events-old / emiter.py View on Github external
def emiter_loop(*, url):
    conn = yield from make_rabbitmq_connection(url=url)
    chan = yield from make_rabbitmq_channel(conn)

    for x in range(10000):
        print("Sleep...")
        yield from asyncio.sleep(1)
        print("Publish: {}".format(x))
        chan.basic_publish(amqp.Message("{}".format(x)), "events")
github jesuejunior / equeue / equeue / rabbit / publisher.py View on Github external
body: The message to be published. If none, message_dict is published.
        
        It also works as a context manager:
        with Publisher(**options) as queue:
            for msg in msgs:
                queue.put(msg)
        """
        if exchange is None:
            exchange = self.default_exchange or ''
        if body is None:
            try:
                body = json.dumps(message_dict)
            except Exception as e:
                raise SerializationError(e)

        message = Message(body,
                          delivery_mode=2,
                          content_type='application/json',
                          priority=priority
                          )
        return self._try('basic_publish',
                         msg=message,
                         exchange=exchange,
                         routing_key=routing_key)
github galaxyproject / galaxy-beta1 / scripts / galaxy_messaging / client / amqp_publisher.py View on Github external
def handle_scan(states, amqp_config, barcode):
    if states.get(barcode[:2], None):
        values = dict( BARCODE=barcode[2:],
                       STATE=states.get(barcode[:2]),
                       API_KEY=amqp_config['api_key'] )
        print values
        data = xml % values
        print data
        conn = amqp.Connection(host=amqp_config['host']+":"+amqp_config['port'],
                               userid=amqp_config['userid'],
                               password=amqp_config['password'],
                               virtual_host=amqp_config['virtual_host'],)

        chan = conn.channel()
        msg = amqp.Message(data,
                           content_type='text/plain',
                           application_headers={'msg_type': 'sample_state_update'})
        msg.properties["delivery_mode"] = 2
        chan.basic_publish(msg,
                           exchange=amqp_config['exchange'],
                           routing_key=amqp_config['routing_key'])
        chan.close()
        conn.close()