pika

RabbitMQ pika.exceptions.ConnectionClosed

杀马特。学长 韩版系。学妹 提交于 2019-12-03 13:55:09
I tried to send message and receive message using RabbitMQ. I dont have computer science background, the terms I used could not be very accurate. I try to copy the tutorial file: When submitting my html form, my python script (cgi) the message is submitting to the queue connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() channel.queue_declare(queue='task_queue', durable=True) message = PN channel.basic_publish(exchange='', routing_key='task_queue', body=message, properties=pika.BasicProperties( delivery_mode = 2, # make message

RabbitMQ, Pika and reconnection strategy

大憨熊 提交于 2019-12-03 12:27:53
问题 I'm using Pika to process data from RabbitMQ. As I seemed to run into different kind of problems I decided to write a small test application to see how I can handle disconnects. I wrote this test app which does following: Connect to Broker, retry until successful When connected create a queue. Consume this queue and put result into a python Queue.Queue(0) Get item from Queue.Queue(0) and produce it back into the broker queue. What I noticed were 2 issues: When I run my script from one host

Error “unknown delivery tag” occurs when i try ack messages to RabbitMQ using pika (python)

孤者浪人 提交于 2019-12-03 04:49:14
I want process messages in few threads but i'm getting error during execute this code: from __future__ import with_statement import pika import sys from pika.adapters.blocking_connection import BlockingConnection from pika import connection, credentials import time import threading import random from pika.adapters.select_connection import SelectConnection from pika.connection import Connection import traceback def doWork(body, args, channel): r = random.random() time.sleep(r * 10) try: channel.basic_ack(delivery_tag=args.delivery_tag) except : traceback.print_exc() auth = credentials

Python and RabbitMQ - Best way to listen to consume events from multiple channels?

落爺英雄遲暮 提交于 2019-12-03 04:33:10
问题 I have two, separate RabbitMQ instances. I'm trying to find the best way to listen to events from both. For example, I can consume events on one with the following: credentials = pika.PlainCredentials(user, pass) connection = pika.BlockingConnection(pika.ConnectionParameters(host="host1", credentials=credentials)) channel = connection.channel() result = channel.queue_declare(Exclusive=True) self.channel.queue_bind(exchange="my-exchange", result.method.queue, routing_key='*.*.*.*.*') channel

Pika 连接 rabbitmq 集群

匿名 (未验证) 提交于 2019-12-03 00:03:02
原文: https://blog.csdn.net/Tech_Salon/article/details/82890431 使用 Pika 连接 rabbitmq 集群 使用 python 编程经常会用到 pika 来向 rabbitmq 发送消息,单个 rabbitmq 节点连接比较简单,本文介绍使用 rabbitmq 集群情况下的连接方式。 vip 连接方式 在 client 与 rabbitmq server 之间通过 haproxy 等负载均衡来提供 vip,我使用的环境就是采用这种方式,但是遇到某一节点挂掉时再访问 vip 连接 rabbitmq 集群会连接失败,常见 log 如下: <URLParameters host=10.10.11.1 port=5672 virtual_host=/ ssl=False> DEBUG:pika.adapters.select_connection:Using EPollPoller DEBUG:pika.callback:Added: {'callback': <bound method SelectConnection._on_connection_start of <SelectConnection CLOSED socket=None params=<URLParameters host=10.10.11.1 port

RabbitMQ队列

一个人想着一个人 提交于 2019-12-02 16:42:07
为啥要使用MQ 以常见的订单系统为例,用户点击【下单】按钮之后的业务逻辑可能包括:扣减库存、生成相应单据、发红包、发短信通知。在业务发展初期这些逻辑可能放在一起同步执行,随着业务的发展订单量增长,需要提升系统服务的性能,这时可以将一些不需要立即生效的操作拆分出来异步执行,比如发放红包、发短信通知等。这种场景下就可以用 MQ ,在下单的主流程(比如扣减库存、生成相应单据)完成之后发送一条消息到 MQ 让主流程快速完结,而由另外的单独线程拉取MQ的消息(或者由 MQ 推送消息),当发现 MQ 中有发红包或发短信之类的消息时,执行相应的业务逻辑。 MQ的介绍 MQ 全称为 Message Queue , 消息队列( MQ )是一种应用程序对应用程序的通信方法。 MQ 是消费-生产者模型的一个典型的代表,一端往消息队列中不断写入消息,而另一端则可以读取队列中的消息。消息发布者只管把消息发布到 MQ 中而不用管谁来取,消息使用者只管从 MQ 中取消息而不管是谁发布的。这样发布者和使用者都不用知道对方的存在。 你可以想想在生活中的一种场景:当你把信件的投进邮筒,邮递员肯定最终会将信件送给收件人。我们可以把MQ比作 邮局和邮递员。 MQ和邮局的主要区别是,它不处理消息,但是,它会接受数据、存储消息数据、转发消息 队列,生产者,消费者 队列是RabbitMQ的内部对象,用于存储消息。生产者

Pika BlockingConnection & RabbitMQ : connection closed

时光怂恿深爱的人放手 提交于 2019-12-02 11:29:27
问题 I have 2 rabbitmq in cluster load balanced by an Azure Internal Load Balancer. The client connect to the LB with BlockingConnection . When there a are message exchanged by the clients, everything works fine. But when there is no activity, it seems my clients are disconnected and and not able to receive messages anymore. I am wondering if there is a solution to this problem ? I assume the load balancer or rabbitmq is closing the connection due to inactivity. I wanted to let pika trigger some

Pika BlockingConnection & RabbitMQ : connection closed

泪湿孤枕 提交于 2019-12-02 06:13:40
I have 2 rabbitmq in cluster load balanced by an Azure Internal Load Balancer. The client connect to the LB with BlockingConnection . When there a are message exchanged by the clients, everything works fine. But when there is no activity, it seems my clients are disconnected and and not able to receive messages anymore. I am wondering if there is a solution to this problem ? I assume the load balancer or rabbitmq is closing the connection due to inactivity. I wanted to let pika trigger some heartbeat to rabbitmq (so that the load balancer keep the connection opened) but didn't find any good

RabbitMQ使用介绍2—Work queues

匆匆过客 提交于 2019-12-02 04:02:29
Work queues 接下来是part2 在这一项中,我们创建一个工作队列,用于在多个工作者之间分配耗时的任务。 Work Queues的主要思想是,避免立即执行资源密集的任务而不得不等待其执行完成。我们将任务封装为消息并将其发送到队列中,在后台运行的一个工作进程将会弹出任务并最终执行该任务,当你管理许多工作节点时,任务就会在他们之间共享。 这个概念在web应用程序中尤其有用,因为在一个短HTTP请求窗口中不可能处理复杂的任务 下面我们发送一个特殊的String,用Thread.sleep()辅助,来模拟一些耗时的工作,用点来简单表示一个任务的复杂度,例如Hello.表示此任务需要两秒进行处理。 我们将在原来生产者的基础上修改一些代码,文件名叫send_work.py: import pika import sys connection = pika.BlockingConnection(pika.ConnectionParameters( 'localhost'))#默认端口5672,可不写 #创建通道,声明一个管道,在管道里发送消息 channel = connection.channel() #在管道里声明queue channel.queue_declare(queue='hello') message = ''.join(sys.argv[1:]) or "Hello

RabbitMQ之RPC(Remote procedure call )

自闭症网瘾萝莉.ら 提交于 2019-12-01 13:21:15
RPC(远程过程调用)   解决的问题:之前的模式都是基于一对一的发,另外端收到,不能继续发。   使用多个队列对多个消费者之间分配耗时的任务    客服端 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 4 import pika 5 import uuid 6 7 8 class FibonacciRpcClient(object): 9 10 def __init__(self): 11 self.credentials = pika.PlainCredentials('admin', 'admin123456') 12 self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.1.6', credentials=self.credentials)) 13 self.channel = self.connection.channel() 14 15 result = self.channel.queue_declare(queue='', exclusive=True) 16 self.callback_queue = result.method.queue 17 18 self.channel.basic