Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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
: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)
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()
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
)
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")
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)
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()