rabbitmq介绍及基本使用

Posted jintian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rabbitmq介绍及基本使用相关的知识,希望对你有一定的参考价值。

开发语言erlang  爱立信公司

技术图片
import pika


credentials = pika.PlainCredentials(alex, alex123)
connection = pika.BlockingConnection(pika.ConnectionParameters(
    192.168.14.52,credentials=credentials))

channel = connection.channel() #建立了rabbit 协议的通道

# 声明queue
channel.queue_declare(queue=hello)

# n RabbitMQ a message can never be 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()
sender1
技术图片
import pika
import time

credentials = pika.PlainCredentials(alex, alex123)
connection = pika.BlockingConnection(pika.ConnectionParameters(
    192.168.14.52,credentials=credentials))

channel = connection.channel()

# You may ask why we declare the queue again ? we have already declared it in our previous code.
# We could avoid that 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)


def callback(ch, method, properties, body):

    print("received msg...start processing....",body)
    time.sleep(20)
    print(" [x] msg process done....",body)


channel.basic_consume(callback,
                      queue=hello,
                      no_ack=True)

print( [*] Waiting for messages. To exit press CTRL+C)
channel.start_consuming()
receive1

技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片

以上是关于rabbitmq介绍及基本使用的主要内容,如果未能解决你的问题,请参考以下文章

RabbitMQ使用介绍及实例

RabbitMQ的基本介绍及与Spring整合

RabbitMQ,Apache的ActiveMQ,阿里RocketMQ,Kafka,ZeroMQ,MetaMQ,Redis也可实现消息队列,RabbitMQ的应用场景以及基本原理介绍,RabbitMQ

RabbitMQ 实现实现基本通信及订单处理

RabbitMQ介绍及安装部署

1.rabbitmq的介绍和基本使用