#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika
span>.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello'
;)
print ' [*] Waiting for messages. To exit press CTRL+C'
def callback(ch, method, properties, body):
print " [x] Received %r" % (body,)
channel.basic_consume(callback,
queue='hello',
no_ack=True)
channel.start_consuming()
Receiving.py
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
print ' [*] Waiting for messages. To exit press CTRL+C'
def callback(ch, method, properties, body):
print " [x] Received %r" % (body,)
channel.basic_consume(callback,
queue='hello',
no_ack=True)
channel.start_consuming()
Sending.py
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
'localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello World!')
print " [x] Sent 'Hello World!'"
connection.close()
'Python' 카테고리의 다른 글
rrdmod (0) | 2017.02.03 |
---|---|
Django + djangorestframework + django_rest_swagger 시작 (0) | 2017.02.01 |
s3 example (0) | 2016.12.28 |
daemonizing (0) | 2016.12.22 |
Threading (0) | 2016.12.22 |