python rabbitmq send
#!/usr/bin/env python
#-*- coding: utf8 -*-
import pika
import traceback
try:
connection = pika.BlockinGConnection(pika.ConnectionParameters(host='192.168.4.226'))
channel = connection.channel()
except:
print traceback.print_exc()
def RabbitMQ_send(abcde):
try:
channel.queue_declare(queue='abcde')
except:
print traceback.print_exc()
try:
mess = "<message><name>abcde</name><item key='abcde'>%s</item></message>" %abcde
channel.basic_publish(exchange='',
routing_key='abcde',
body = mess)
print '[x] Send abcde'
except:
print traceback.print_exc()
try:
connection.close()
except:
print traceback.print_exc()
if __name__ == "__main__":
sc = rabbitMQ_send('abcde')
相关文章