博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ubuntu 12.04安装配置rabbitmq
阅读量:7210 次
发布时间:2019-06-29

本文共 3419 字,大约阅读时间需要 11 分钟。

hot3.png

ubuntu 12.04安装配置rabbitmq

在安装rabbitmq之前,需要先安装一些依赖关系,比如erlang,下面介绍安装方法:

一. 安装erlang

1.安装依赖关系包

sudo apt-get install build-essential libncurses5-dev m4 libssl-dev unixodbc unixodbc-dev libc6 freeglut3-dev libwxgtk2.8-dev xsltproc fop g++ build-essential

2.下载源码包

wget https://packages.erlang-solutions.com/erlang/esl-erlang/FLAVOUR_1_general/esl-erlang_19.1-2~ubuntu~precise_i386.deb

3.安装

sudo dpkg -i esl-erlang_19.1-2~ubuntu~precise_i386.deb

4.验证安装成功

erl

  输出如下信息:

Erlang /OTP19 (erts-8.1) [source-77fb4f8] [async-threads:10] [hipe] [kernel-poll:false]Eshell V8.1 (abort with ^G)1>

二. 安装rabbitmq-server

1.下载安装包

wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.4.3/rabbitmq-server_3.4.3-1_all.deb

2.安装

sudo dpkg -i rabbitmq-server_3.4.3-1_all.deb

3.重启rabbitmq-server服务

sudo /etc/init.d/rabbitmq-server restart

4.查看rabbitmq服务

ps -ef |grep rabbitmq

5.rabbitmq web管理页面插件安装

rabbitmq-plugins enable rabbitmq_management

  安装完成后即可通过 进行访问。

三. 安装setuptools

1.下载安装包

wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz

2.解压

tar -zxvf setuptools-0.6c11.tar.gz

3.进入setuptools-0.6c11源目录

cd setuptools-0.6c11

4.编译

python setup.py build

5.安装

python setup.py install

四. 安装AMQP python客户端pika

1.下载安装包

wget https://pypi.python.org/packages/source/p/pika/pika-0.9.14.tar.gz#md5=b99aad4b88961d3c7e4876b8327fc97c

2.解压

tar zxvf pika-0.9.14.tar.gz

3.安装

python setup.py install

五. 测试实例

  采用最简单的情况作为实例,发送消息,接收并打印出来即可。如下图所示:

send.py

#!/usr/bin/env python  import pika  # 1. Establish a connection with RabbitMQ server.  connection = pika.BlockingConnection(pika.ConnectionParameters(                 'localhost'))  channel = connection.channel()    # 2. Create a queue to which the message will be delivered, let's name it 'hello'  channel.queue_declare(queue='hello')    # 3. Use a default exchange identified by an empty string, which allows us to specify  #    exactly to which queue the message should go. The queue name needs to be specified  #    in the routing_key parameter:  channel.basic_publish(exchange='',                        routing_key='hello',                        body='Hello World!')  print " [x] Sent 'Hello World!'"    # 4. Close the connection  connection.close()

recv.py

#!/usr/bin/env python  import pika    # 1. Establish a connection with RabbitMQ server  connection = pika.BlockingConnection(pika.ConnectionParameters(          host='localhost'))  channel = connection.channel()    # 2. Make sure that the queue exists,run the command as many times as we like, and only one will be created.  channel.queue_declare(queue='hello')    print ' [*] Waiting for messages. To exit press CTRL+C'    # 3. Define a callback function.Whenever we receive a message,   #    this callback function is called by the Pika library.  def callback(ch, method, properties, body):      print " [x] Received %r" % (body,)    # 4. Subscribe the callback function to a queue.  #    Tell RabbitMQ that this particular callback function should receive messages from our hello queue.  channel.basic_consume(callback,                        queue='hello',                        no_ack=True)    # 5. Enter a never-ending loop that waits for data and runs callbacks whenever necessary.  channel.start_consuming()

  测试结果

python send.py——>[x] Sent 'Hello World!'python recv.py——>[*] Waiting for messages. To exit press CTRL+C   [x] Received 'Hello World!' [x] Done

转载于:https://my.oschina.net/u/1179767/blog/752042

你可能感兴趣的文章
质因子分解
查看>>
Django搭建个人博客:文章标签功能
查看>>
Docker学习笔记
查看>>
61. Rotate List
查看>>
Linux CTF 逆向入门
查看>>
LeetCode-数组-三数之和
查看>>
Alain 菜单权限控制
查看>>
spring + angular 实现导出excel
查看>>
Linux环境升级node版本
查看>>
Linux快速复制或删除大量小文件
查看>>
怎么解决在微信中不能直接下载APP(APK)的方案
查看>>
从0到1,了解NLP中的文本相似度
查看>>
【C++】 54_被遗弃的多重继承 (下)
查看>>
一篇文章入门Flask
查看>>
Redis笔记(一)
查看>>
前端开发如何做好本地接口模拟
查看>>
Vue项目部署遇到的问题及解决方案
查看>>
Python 基础起步(一)写在开篇的话,写给同为小白的你
查看>>
webpack入门学习手记(一)
查看>>
GraphQL —— 标量类型
查看>>