zoukankan      html  css  js  c++  java
  • Python3-RabbitMQ 3.7.2学习——Hello World(二)

    RabbitMQ环境搭建好了,接下来就是学习编程的入门级hello world.

    在运行程序前,要先确保开启RabbitMQ服务

    然后安装pika,命令:pip install pika

    1.创建一个python工程,我创建的名为RabitMQ_Demo

    2,创建一个send.py

    #!/usr/bin/env python3.5.2
    # -*- coding: utf-8 -*-
    
    import pika
    
    connection = pika.BlockingConnection(pika.ConnectionParameters(
            host='localhost'))
    channel = connection.channel()
    
    
    channel.queue_declare(queue='hello')
    
    channel.basic_publish(exchange='',
                          routing_key='hello',
                          body='Hello World!')
    print(" [x] Sent 'Hello World!'")
    connection.close()

    3,创建一个receive.py

    #!/usr/bin/env python3.5.2
    # -*- coding: utf-8 -*-
    
    import pika
    
    connection = pika.BlockingConnection(pika.ConnectionParameters(
            host='localhost'))
    channel = connection.channel()
    
    
    channel.queue_declare(queue='hello')
    
    def callback(ch, method, properties, body):
        print(" [x] Received %r" % body)
    
    channel.basic_consume(callback,
                          queue='hello',
                          no_ack=True)
    
    print(' [*] Waiting for messages. To exit press CTRL+C')
    channel.start_consuming()

    4.运行。

      (1),先运行receive.py

               

      (2),然后运行send.py

              

              

    就此,helloworld就完了,接下来,就去网站上去找教程,加深学习。

    参考:http://blog.csdn.net/zhangfh1990/article/details/72676411

  • 相关阅读:
    Delphi中的构造函数的override的问题
    一个很初级的错误 Destructor忘记override导致内存泄露
    WPF 详解模板
    再说WCF Data Contract KnownTypeAttribute
    ADO.NET Data Service
    Using ADO.NET Data Service
    资源:Localization – 本地化
    Dynamic Resource – 动态资源
    应用开发之Linq和EF
    语法之多线程
  • 原文地址:https://www.cnblogs.com/yanjj/p/8183795.html
Copyright © 2011-2022 走看看