rabbitmq基础

来源:互联网 发布:mac itunes 铃声找不到 编辑:程序博客网 时间:2024/06/06 09:29

product.py

import pikaconnection = 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] Send 'Hello World'")connection.close()

cousumer.py

import pikaconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))channel = connection.channel()channel.queue_declare(queue='hello')def callable(ch, method, properties, body):    print("[x] Received %r" % body)channel.basic_consume(callable,                      queue='hello',                      no_ack=True)print(' [*] Waiting for messages')channel.start_consuming()
原创粉丝点击