首页 > 技术文章 > Python生产者发送消息脚本rabbitmq

-pengfei 2018-04-24 16:14 原文

# !/usr/bin/env python
import pika
credentials = pika.PlainCredentials('admin','yaochizaocan')
connection = pika.BlockingConnection(pika.ConnectionParameters(
'59.110.123.17',8008,'/',credentials))
channel = connection.channel()

# 声明queue
channel.queue_declare(queue='balance')

# n RabbitMQ a message can never be sent directly to the queue, it always needs to go through an exchange.
cnt = 4000000
while (cnt !=0):

channel.basic_publish(exchange='',
routing_key='balance',
body='H')
cnt -=1
print(4000000-cnt," [x] 1")
connection.close()

推荐阅读