zoukankan      html  css  js  c++  java
  • 【消息队列】之 RabbitMQ安装

    RabbitMQ

    环境

    centos 7

    安装

    vi /etc/yum.repos.d/rabbitmq-erlang.repo
    

    [rabbitmq-erlang]
    name=rabbitmq-erlang
    baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/21/el/7
    gpgcheck=1
    gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
    repo_gpgcheck=0
    enabled=1

    yum install erlang socat -y
    
    rpm -Uvh https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.18/rabbitmq-server-3.7.18-1.el7.noarch.rpm
    
    systemctl start rabbitmq-server
    systemctl enable rabbitmq-server
    systemctl status rabbitmq-server
    

    安装ui插件

    rabbitmq-plugins enable rabbitmq_management
    chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/
    

    创建账号授权

    rabbitmqctl add_user admin rabbitmq
    rabbitmqctl set_user_tags admin administrator
    rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
    
    systemctl restart rabbitmq-server
    

    关闭防火墙

    iptables -F
    

    登陆

    http://ip:15672 输入账号密码 admin/rabbitmq

    python测试

    生产者

    #!/usr/bin/env python   
    # -*- coding: UTF-8 -*- 
    import pika
    #连上rabbitMQ
    connection=pika.BlockingConnection(pika.ConnectionParameters('localhost'))
    channel=connection.channel()
    
    #声明queue
    channel.queue_declare(queue='hello1')
    
    #n RabbitMQ a message can never be sent directly to the queue,it always needs to go through an exchange.
    #向队列里发数据
    import json
    data = json.dumps({"a":1})
    
    
    channel.basic_publish(exchange='',
                          routing_key='hello1',
                          body=data)
    print("[x]Sent'HelloWorld!'")
    connection.close()
    
    

    消费者

    import poka
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='127.0.0.1', port=5672))
    channel = connection.channel()
    channel.queue_declare(queue='hello1')
    #回调函数
    def callback(ch, method, properties, body):
    	def callback(ch, method, properties, body):
    
    channel.basic_consume(queue="hello1",auto_ack=True,on_message_callback=callback)
    #监听
    channel.start_consuming()
    
    
  • 相关阅读:
    Vue异步数据交互 promise axios async fetch
    JS数组或对象转为JSON字符换 JavaScript JSON.stringify()
    JS返回数组的最大值与最小值
    Error: Cannot find module './application'
    Express框架
    NodeJS项目制作流程
    模板引擎art-template
    基于NodeJS的网络响应原理与HTTP协议
    leetcode 953. 验证外星语词典 做题笔记
    leetcode 771. 宝石与石头 做题笔记
  • 原文地址:https://www.cnblogs.com/gooooodmorning/p/13492749.html
Copyright © 2011-2022 走看看