RabbitMQ Learn Record

Language: Python

Protocols Base: AMQP 0-9-1

To communicate, firstly build a Connection with server.


     connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))

After Connection established, we get a channel from the connection:
   
     channel = connection.channel()

Because rabbitMQ based on queue message, we to create a queue which the message will be delivered.


  channel.queue_declare(queue='hello')


After queue established, we start to send message:
 
    channel.basic_publish(exchange='', routing_key='hello', body='hello world')

The parameter body is the message we'll send

After that, we close the connection. We don't have to close the channel or other operation like sql operation.
  connection.close()





原文地址:https://www.cnblogs.com/-Doraemon/p/4700059.html