• rabbitmq


    一 、安装:

    参考:https://www.cnblogs.com/wt11/p/5970297.html
    https://blog.csdn.net/rickey17/article/details/72756766

    https://www.cnblogs.com/liuchuanfeng/p/6813205.html

    执行sudo apt-get install rabbitmq-server报错:
    The following packages have unmet dependencies:
     linux-generic : Depends: linux-headers-generic (= 4.4.0.127.133) but 4.4.0.109.114 is to be installed
     rabbitmq-server : Depends: erlang-nox (>= 1:13.b.3) but it is not going to be installed or
                                esl-erlang but it is not installable
    #### 执行
    sudo apt-get install -f 
    
    sudo apt-get install erlang-nox
    sudo apt-get install rabbitmq-server
    

    二、注册用户和管理:

    Ubuntu上安装和使用RabbitMQ
    1. 安装RabbitMQ服务软件包
    
    输入以下命令进行安装
    
    #apt install rabbitmq-server
    
     
    
    2.安装完成后在rabbitMQ中添加用户
    
    命令:#rabbitmqctl add_user username password
    
    将用户设置为管理员(只有管理员才能远程登录)
    
    命令:#rabbitmqctl set_user_tags username administrator
    
    同时为用户设置读写等权限
    
    命令:#rabbitmqctl set_permissions -p / username ".*" ".*" ".*"
    
     
    
    3.安装RabbitMQ监控管理插件进行RabbitMQ的管理
    
    命令:#rabbitmq-plugins enable rabbitmq_management
    
    插件rabbitmq_management启动成功后就可以通过web页面进行RabbitMQ的监控和管理
    
     
    
    4.使用rabbitmq_management插件进行监控和管理
    
    使用firefox浏览器登录:http://localhost:15672
    
    在登录页面使用 guest/guest用户名和密码登录RabbitMQ管理系统,在系统中可以对RabbitMQ服务进行channel,queue,用户等的管理
    
     
    
    PS:Guest账号不能远程登录。
    
    如果还不能远程访问或远程登录检查是不是5672, 15672端口没有开放!!!!!!
    

    三、简单使用:

    参考:https://www.cnblogs.com/kerwinC/p/5967584.html

    生产者:
    # !/usr/bin/env python
    import pika
    credentials = pika.PlainCredentials('admin','123456')
    connection = pika.BlockingConnection(pika.ConnectionParameters(
        '192.168.56.19',5672,'/',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.
    channel.basic_publish(exchange='',
                          routing_key='balance',
                          body='Hello World!')
    print(" [x] Sent 'Hello World!'")
    connection.close()
    
    
    
    消费者:
    # _*_coding:utf-8_*_
    __author__ = 'Alex Li'
    import pika
    
    credentials = pika.PlainCredentials('admin','123456')
    connection = pika.BlockingConnection(pika.ConnectionParameters(
        '192.168.56.19',5672,'/',credentials))
    channel = connection.channel()
    
    # You may ask why we declare the queue again ‒ we have already declared it in our previous code.
    # We could avoid that if we were sure that the queue already exists. For example if send.py program
    # was run before. But we're not yet sure which program to run first. In such cases it's a good
    # practice to repeat declaring the queue in both programs.
    channel.queue_declare(queue='balance')
    
    
    def callback(ch, method, properties, body):
        print(" [x] Received %r" % body)
    
    
    channel.basic_consume(callback,
                          queue='balance',
                          no_ack=True)
    
    print(' [*] Waiting for messages. To exit press CTRL+C')
    channel.start_consuming()
  • 相关阅读:
    java 学习之JVM深入分析(一)
    选择排序算法实现十个1100的随机数的排序
    spring基础知识概述
    mybatis 总结一
    ACM之java判断回文数
    Spring mvc框架
    C#实现窗体最小化到状态栏,双击运行时又能正常显示窗体
    Android调用相机并将照片存储到SD卡上实现方法
    c#中如何让一个窗体在另一个旁边
    C#实现获取时间
  • 原文地址:https://www.cnblogs.com/lajiao/p/9161775.html
Copyright © 2020-2023  润新知