Get ready:
1. Download the support environment for the Elang language http://www.erlang.org/download.html (RABBITMQ developed using it)
2. Download the RABBITMQ software http://www.rabbitmq.com/releases/rabbitmq-server/(depending on your system selection)
3. Install ELANG,RABBITMQ, and configure the environment variables, my is windows7, the steps are as follows:
A. New variable: Erlang_home=d:\program files\erl6.1, then add%erlang_home%\bin in Path;
B. New variable: Rabbitmq_server=d:\program files\rabbitmq_server-3.3.4, then add%rabbitmq_server%\sbin in Path;
C. Run Sbin/rabbitmq-server.bat, start the RABBITMQ server effect as
Working with Python RABBITMQ
1. Download the Pika Support Package (pip install pika)
2. Message delivery received by the producer consumer model
Generated by party code productor.py
1# __author__ ='STEVEN'2 Import Pika3 def b ():4 #建立socket5Connection = Pika. Blockingconnection (Pika. Connectionparameters (host='localhost'))6 #声明一个管道7Piple =Connection.channel ()8 #创建一个队列9Piple.queue_declare ('Hello')Ten #发送消息 OnePiple.basic_publish (exchange="', routing_key='Hello', body='Oh, hello.') APrint'[x] Sent message: Hello') - connection.close () -B ()
Consumer Square Code consumer.py
1 #__author__ = ' STEVEN '2 ImportPika3 #Create a socket link4Connection = Pika. Blockingconnection (Pika. Connectionparameters ('localhost'))5 #Creating Pipelines6Channel =Connection.channel ()7 #Create a queue8Channel.queue_declare ('Hello')9 #declaring a callback functionTen defCallback (ch,method,properties,body): One Print('[x] recieved message%r'%Body.decode ()) A #Call the callback function if the message is accepted, ready to accept the message -Channel.basic_consume (callback,queue='Hello', no_ack=True) - Print('[*] is waiting for recieve mess press CTRL + C to Eixt') the #Start Consumer News -Channel.start_consuming ()
Python uses RABBITMQ for simple message forwarding