Python Operation RABBITMQ

Source: Internet
Author: User
Tags message queue rabbitmq

RABBITMQ is a complete, reusable enterprise messaging system based on AMQP. He follows the Mozilla Public License open source agreement.

MQ is all called the message queue, and Message Queuing (MQ) is an application-to-application communication method. Applications communicate by reading and writing messages to and from the queue (data for the application), without requiring a dedicated connection to link them. Message passing refers to the process of communicating between programs by sending data in a message, rather than by directly invoking each other, and directly invoking techniques such as remote procedure calls. Queuing refers to an application communicating through a queue. The use of queues removes the requirement that both the receiving and sending applications execute concurrently.

RABBITMQ Installation

Yum installation you can also use the source code to install

Installation configuration Epel Source

RPM-IVH http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

Installing Erlang

# yum-y Install Erlang

Installing RABBITMQ

# yum-y Install Rabbitmq-server

Note: Service Rabbitmq-server start/stop

Install API

pip Install Pika or Easy_install Pika or source https://pypi.python.org/pypi/pika

To achieve the simplest queue communication

Send End

#!/usr/bin/env pythonImportPika Connection=Pika. Blockingconnection (Pika. Connectionparameters ('localhost')) Channel=Connection.channel ()#declaring a queueChannel.queue_declare (queue='Hello') #n RabbitMQ A message can never is sent directly to the queue, it always needs to go through an exchange.Channel.basic_publish (exchange="', Routing_key='Hello', Body='Hello world!')Print("[x] Sent ' Hello world! '") Connection.close ()

Receive End

#_*_coding:utf-8_*___author__='Alex Li'ImportPika Connection=Pika. Blockingconnection (Pika. Connectionparameters ('localhost')) Channel=Connection.channel ()#May ask why we declare the queue again? We had already declared it in our previous code.#we could avoid so 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='Hello') defCallback (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 ()

Python Action RABBITMQ

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.