Menu
new_task.py
The following are 30 code examples for showing how to use pika.ConnectionParameters.These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. Pika详解(二) BlockingConnection comprel 2019-07-04 00: 收藏 5 分类专栏: rabbitmq 文章标签: pika rabbitmq python BlockingConnection.
#!/usr/bin/env python |
importsys |
importpika |
connection=pika.BlockingConnection(pika.ConnectionParameters( |
'localhost')) |
channel=connection.channel() |
channel.queue_declare(queue='hello', durable=True) |
channel.basic_qos(prefetch_count=1) |
message=' '.join(sys.argv[1:]) or'Hello World!' |
channel.basic_publish(exchange=', |
routing_key='hello', |
body=message, |
properties=pika.BasicProperties( |
delivery_mode=2, # make message persistent |
)) |
print' [x] Sent '%r'!'%message |
connection.close() |
Raw |
![Pika blocking connection Pika blocking connection](https://www.freesion.com/images/360/bed1d33fc22697d971fe265ea802f9b8.png)
worker_async.py
#!/usr/bin/env python |
'' |
Create multiple RabbitMQ connections from a single thread, using Pika and multiprocessing.Pool. |
Based on tutorial 2 (http://www.rabbitmq.com/tutorials/tutorial-two-python.html). |
'' |
importmultiprocessing |
importtime |
importpika |
defcallback(ch, method, properties, body): |
print' [x] %r received %r'% (multiprocessing.current_process(), body,) |
time.sleep(body.count('.')) |
# print ' [x] Done' |
ch.basic_ack(delivery_tag=method.delivery_tag) |
defconsume(): |
connection=pika.BlockingConnection(pika.ConnectionParameters( |
'localhost')) |
channel=connection.channel() |
channel.queue_declare(queue='task_queue', durable=True) |
channel.basic_consume(callback, |
queue='hello') |
print' [*] Waiting for messages. To exit press CTRL+C' |
try: |
channel.start_consuming() |
exceptKeyboardInterrupt: |
pass |
workers=5 |
pool=multiprocessing.Pool(processes=workers) |
foriinxrange(0, workers): |
pool.apply_async(consume) |
# Stay alive |
try: |
whileTrue: |
continue |
exceptKeyboardInterrupt: |
print' [*] Exiting..' |
pool.terminate() |
pool.join() |
Pika Blockingconnection Exception
commented Aug 15, 2020 •
![Connection Connection](https://img2018.cnblogs.com/blog/1525781/201901/1525781-20190102122338015-1382930712.png)
I'm happy to see an example of rabbitmq with multiprocessing. Have you tried to implement this approach but with a shared connection? Arturia matrix 12 v2 v2 3 2 1889 download free. connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) .. for i in xrange(0, workers): pool.apply_async(consume, args=(connection, )) .. def consume(connection): channel = connection.channel() .. I can't get it to work. Would appreciate some insight! Thanks! |
Pika Blockingconnection Username And Password
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment