python rabbitmq send

发布时间:2019-09-01 09:51:05编辑:auto阅读(1675)

    #!/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')







关键字

上一篇: python实现ftp上传

下一篇: python set(集合)