RabbitMQ

Posted hinimix

tags:

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

RabbitMQ:
和python queue的区别
线程queue,多个线程之间数据同步用
进程queue,用于父进程与子进程交互,或同一父进程下多个子进程之间交互
rabbitmq,两个独立进程之间交互

依赖erlang

producer
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# -*- Author:Hinimix -*-

import pika

creditials = pika.PlainCredentials(admin, Inspiry2018)
conn = pika.BlockingConnection(
    pika.ConnectionParameters("192.168.20.61", 5672, /, creditials)
)

channel = conn.channel()    #声明一个管道

channel.queue_declare(queue=hinimix)

channel.basic_publish(
    exchange=‘‘,            #
    routing_key=hinimix,    #queue名字
    body=hello, world     #内容
)

print("[x] sent ‘hello world")

conn.close()

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# -*- Author:Hinimix -*-

import pika

creditials = pika.PlainCredentials(admin, admin)
conn = pika.BlockingConnection(
    pika.ConnectionParameters("192.168.20.61", 5672, /, creditials)
)

channel = conn.channel()    #声明一个管道

channel.queue_declare(queue=hinimix)

channel.basic_publish(
    exchange=‘‘,            #
    routing_key=hinimix,    #queue名字
    body=hello, world     #内容
)

print("[x] sent ‘hello world")

conn.close()


consumer

 

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# -*- Author:Hinimix -*-

import pika

creditials = pika.PlainCredentials(admin, admin)
conn = pika.BlockingConnection(
    pika.ConnectionParameters("192.168.20.61", 5672, /, creditials)
)

channel = conn.channel()
channel.queue_declare(queue=hinimix)


def callback(ch, method, properties, body):
    print(ch, @@, method,@@, properties,@@, body)
    print("[x] received %r" % body)

channel.basic_consume(
    callback,           # 如果收到消息调用callback来处理消息
    queue=hinimix,
    no_ack=True
)

print("[*] waiting for messages.")
channel.start_consuming()

 












以上是关于RabbitMQ的主要内容,如果未能解决你的问题,请参考以下文章

RabbitMQRabbitMQ和Erlang下载与安装步骤—2023超详细最新版

Springboot 整合 RabbitMQrabbitmq介绍:安装,下载,创建队列交换机,5种工作模式

RabbitMQ

RabbitMQ安装

day11

RabbitMQ消息中间件