#send 端
import pika
credentials = pika.PlainCredentials('root', 'Password1')
connection = pika.BlockingConnection(pika.ConnectionParameters('10.3.151.86',5672,'/',credentials))
channel = connection.channel() #通過connection實例創建一個channel管道
channel.queue_declare(queue='hello') #在管道中創建一個隊列
channel.basic_publish(exchange='',routing_key='hello',body='Hello Wfffforld!')
connection.close()
#receive 端
import pika
credentials = pika.PlainCredentials('root', 'Password1')
connection = pika.BlockingConnection(pika.ConnectionParameters('10.3.151.86',5672,'/',credentials))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch,method,properties,body):
print(" [x] Received %r" % body)
channel.basic_consume(callback,queue='hello',no_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()