演示環境測試測試「
consumer.pypython
1 import pika 2 3 credentials = pika.PlainCredentials('pymq','123123') 4 connection = pika.BlockingConnection(pika.ConnectionParameters( 5 '10.1.120.131',5672,'test_host',credentials)) 6 channel = connection.channel() 7 8 channel.queue_declare(queue='balance') 9 10 11 def callback(ch, method, properties, body): 12 print(" [x] Received %r" % body) 13 print(bytes.decode(body)) 14 15 16 channel.basic_consume(callback, 17 queue='balance', 18 no_ack=True) 19 20 print(' [*] Waiting for messages. To exit press CTRL+C') 21 channel.start_consuming()
server.pyide
1 import pika 2 3 credentials = pika.PlainCredentials('pymq', '123123') 4 connection = pika.BlockingConnection(pika.ConnectionParameters( 5 '10.1.120.131', 5672, 'test_host', credentials 6 )) 7 channel = connection.channel() 8 9 #queue 10 channel.queue_declare(queue='balance') 11 12 channel.basic_publish( 13 exchange='', 14 routing_key='balance', 15 body='演示環境測試測試') 16 17 connection.close()