RABBITMQ Installation and command introduction and Python program simulation for producers and consumers

Source: Internet
Author: User
Tags rabbitmq yum repolist

" Introduction "

RABBITMQ is a amqp on the basis of a complete, reusable enterprise messaging system. He follows the mozilla public License Open Source protocol

RABBITMQ is a popular open source Message Queuing system developed in Erlang language.

RABBITMQ is the standard implementation of the AMQP (Advanced Message Queuing protocol)

Official website: http://www.rabbitmq.com/


" Install "

Way: yum/rpm

System environment

[[Email protected]_server scripts]# ifconfig | Sed-n ' S#.*inet addr:\ (. *\) B.*#\1#GP '

192.168.100.20

[[Email protected]_server scripts]# cat/etc/issue | Grep-i cent

CentOS Release 6.4 (Final)

[Email protected]_server scripts]# Yum repolist |grep Epel

* epel:mirrors.aliyun.com

Epel Extra Packages for Enterprise Linux 6-x86_64 12,244

[[Email Protected]_server scripts]#

Yum Install-y rabbitmq-server

After the installation is successful, view the list of plugins

/usr/lib/rabbitmq/bin/rabbitmq-plugins List

Start the Rabbitmq_management plugin

/usr/lib/rabbitmq/bin/rabbitmq-plugins Enable Rabbitmq_management

Start the program

/etc/init.d/rabbitmq-server start

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7F/A2/wKioL1cm7eCgICsUAACkuf38UZc687.png "title=" Rabbitmq1.png "alt=" Wkiol1cm7ecgicsuaackuf38uzc687.png "/>


" Validate "

[[email protected]_server scripts]# netstat -tulnp |grep 15672tcp         0      0 0.0.0.0:15672                0.0.0.0:*                    LISTEN       3877/beam.smp       [[email protected]_ server scripts]# ps -ef |grep rabbitroot      3837      1  0 11:30 pts/2    00:00:00 /bin/ sh /etc/init.d/rabbitmq-server startroot      3868  3837   0 11:30 pts/2    00:00:00 /bin/bash -c ulimit -s  -c 0 >/dev/null 2>&1 ; /usr/sbin/rabbitmq-serverroot      3869   3868  0 11:30 pts/2    00:00:00 /bin/sh /usr/sbin/ Rabbitmq-serverroot      3876  3869  0 11:30 pts/2     00:00:00 su rabbitmq -s /bin/sh -c /usr/lib/rabbitmq/bin /rabbitmq-server rabbitmq  3877  3876  0 11:30 ?         00:00:55 /usr/lib64/erlang/erts-5.8.5/bin/beam.smp -w w  -k true -a30 -p 1048576 -- -root /usr/lib64/erlang -progname  erl -- -home /var/lib/rabbitmq -- -pa /usr/lib/rabbitmq/lib/rabbitmq_ server-3.1.5/sbin/. /ebin -noshell -noinput -s rabbit boot -sname [email protected]_server  -boot stArt_sasl -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type  error -sasl sasl_error_logger false -rabbit error_logger {file, "/var/log/ Rabbitmq/[email protected]_server.log "} -rabbit sasl_error_logger {file,"/var/log/rabbitmq /[email protected]_server-sasl.log "} -rabbit enabled_plugins_file "/etc/rabbitmq/enabled_ Plugins " -rabbit plugins_dir "/usr/lib/rabbitmq/lib/rabbitmq_server-3.1.5/sbin/. /plugins " -rabbit plugins_expand_dir "/var/lib/rabbitmq/mnesia/[email protected]_ Server-plugins-expand " -os_mon start_cpu_sup false -os_mon start_disksup false  -os_mon start_memsup false -mnesia dir  "/var/lib/rabbitmq/mnesia/[email  Protected]_server "rabbitmq  3951  3877  0 11:30 ?         00:00:00 inet_gethost 4rabbitmq  3952  3951  0 11:30 ?         00:00:00 inet_gethost 4root     19143   1770  0 14:02 pts/2    00:00:00 grep rabbit[[email  protected]_server scripts]#



" Configuration "

The default configuration does not need to be configured


If you need/etc/rabbitmq/you can create a



" Common Commands "

View Queue List

Rabbitmqctl list_queues

View the queue under the default vhost for "/"

Rabbitmqctl list_queues-p "/"

View Vhost List

Rabbitmqctl list_vhosts

Add/Remove Vhost

Rabbitmqctl Add_vhost Vhost_andy
Rabbitmqctl Delete_vhost <VHostPath>

Add Users

Rabbitmqctl add_user Andy ' 12qwaszx '

View User

Rabbitmqctl list_users[[email protected]_server scripts]# rabbitmqctl list_userslisting users ... andy []guest [admin Istrator]

Bind the user to vhost_andy this vhost, and give permissions to <conf> <write> <read>, the user is associated with the administrative rights of a vhost

Rabbitmqctl set_permissions-p Vhost_andy Andy ". *" ". *" ". *"

View User Permissions

Rabbitmqctl list_user_permissions Andy

[Email protected]_server scripts]# Rabbitmqctl list_user_permissions Andy

Listing permissions for user "Andy" ...

Vhost_andy. *. *. *

... done.



"Web Management Connection "

http://192.168.100.20:15672/

Guest/guest Log In


650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7F/A4/wKiom1cm8APyAnHGAACKr32lUtw375.png "title=" Rabbitmq2.png "alt=" Wkiom1cm8apyanhgaackr32lutw375.png "/>




"Python program simulation producer "

Reference official website: http://www.rabbitmq.com/tutorials/tutorial-one-python.html


From the simplest model p-mq--c

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7F/A2/wKioL1cm-YvSTP2wAAAiVPxc1zo857.png "title=" Rabbitmq1.png "alt=" Wkiol1cm-yvstp2waaaivpxc1zo857.png "/>




Cat send.py

#!/usr/bin/env Python#encoding==utf-8#http://cuidehua.blog.51cto.com#from http://www.rabbitmq.com/tutorials/ Tutorial-one-python.htmlimport pikaconnection = 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 ()

Simulate sending 100 messages to this queue in Queue=hello.

For i in {1..100};d o python send.py;d One


Command View queue: (do not specify Vhost queue in default Vhost "/")

[Email protected]_server scripts]# rabbitmqctl list_queues-p "/"

Listing queues ...

Hello 100

... done.


Web-side view

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7F/A4/wKiom1cm-dmiPi7mAABezq7IVCk156.png "title=" Rabbitmq2.png "alt=" Wkiom1cm-dmipi7maabezq7ivck156.png "/>



"Python program simulates consumer consumption "

[[Email protected]_server scripts]# cat receive.py 

#!/usr/bin/env Python#encoding=utf-8#http://cuidehua.blog.51cto.com#from http://www.rabbitmq.com/tutorials/ Tutorial-one-python.htmlimport pikaconnection = Pika. Blockingconnection (Pika. Connectionparameters (host= ' localhost ')) channel = Connection.channel () channel.queue_declare (queue= ' Hello ') #                      Define callback function 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 ()


Execute the consumption, and wait for messages! Until CTRL + C terminates

Python receive.py


View Queue again

[Email protected]_server scripts]# rabbitmqctl list_queues-p "/"

Listing queues ...

Hello 0

... done.


This article is from the "Tridewah operation and maintenance work Road" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1769460

RABBITMQ Installation and command introduction and Python program simulation for producers and consumers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.