pika

Set Timeout for Pika ioloop async (RabbitMQ)

心不动则不痛 提交于 2019-12-10 06:58:29
问题 I need to be able to gracefully stop a consumer (worker) who works in a Pika ioloop. The worker should stop after 60 seconds. Currently processed messages should be finished. I tried to put a connection.close() inside the callback function but that only stopped the current thread and not the complete ioloop. And it gave a terrible error output. Please see line 16 and following in my code: I used the (basic example about Pika ioloop http://pika.github.com/connecting.html#cps-example: from pika

pycharm一部分代码不提示(类似 bug 模块 pika)

被刻印的时光 ゝ 提交于 2019-12-10 03:33:45
本文能解决的问题: linux下(windows 直接试一试解决办法)python交互式tab键有代码提示,而pycharm相同代码无提示的问题. 问题原因: pycharm不运行代码不知道结果类型,所以没有代码提示,而交互式运行了所以有代码提示. 解决办法: 交互式获取类型 type(要获取结果类型的变量名) 或者pycharm只运行前一部分print(type(要获取结果类型的变量名))得到结果类型 然后用类型定义 比如 要定义行结尾加上 # type: 获取到的类型 例子: import pika connection = pika . BlockingConnection ( pika . ConnectionParameters ( '127.0.0.1' ) ) channel = connection . channel ( ) channel . #这里没有代码提示 import pika connection = pika . BlockingConnection ( pika . ConnectionParameters ( '127.0.0.1' ) ) channel = connection . channel ( ) print ( type ( channel ) ) # 运行并从控制台获得类型 # 这个例子的结果 pika.adapters

pika, stop_consuming does not work

一个人想着一个人 提交于 2019-12-10 03:06:12
问题 I'm new to rabbitmq and pika, and is having trouble with stopping consuming. channel and queue setting: connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() channel.queue_declare(queue=new_task_id, durable=True, auto_delete=True) Basically, consumer and producer are like this: consumer: def task(task_id): def callback(channel, method, properties, body): if body != "quit": print(body) else: print(body) channel.stop_consuming(task_id)

How to do a simple Pika SelectConnection to send a message, in python?

徘徊边缘 提交于 2019-12-09 07:33:41
问题 I am trying to convert my code to send rabbitmq messages via Pika instead. I am having a lot of trouble understanding how to send a simple message using an asynchronous connection (such as SelectConnection). In my old code, which I use the amqp library I simply declare a class like this: import amqp as amqp class MQ(): mqConn = None channel = None def __init__(self): self.connect() def connect(self): if self.mqConn is None: self.mqConn = amqp.Connection(host="localhost", userid="dev",

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

こ雲淡風輕ζ 提交于 2019-12-09 05:05:31
问题 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:

Consume multiple queues in python / pika

為{幸葍}努か 提交于 2019-12-09 04:30:20
问题 I am trying to create a consumer that would subscribe to multiple queues, and then process messages as they arrive. The problem is that when there is some data already present in the first queue, it consumes the first queue and never goes to consume the second queue. However, when the first queue is empty, it does go to the next queue, and then consumes both queues simultaneously. I had first implemented threading but want to steer clear of it, when pika library does it for me without much

Python Pika - Consumer into Thread

谁说胖子不能爱 提交于 2019-12-07 18:16:20
问题 I'm working on a Python app with a background thread for consuming message from a RabbitMQ Queue (topic scenario). I start the thread on on_click event of a Button. Here is my code, please take attention on "#self.receive_command()". def on_click_start_call(self,widget): t_msg = threading.Thread(target=self.receive_command) t_msg.start() t_msg.join(0) #self.receive_command() def receive_command(self): syslog.syslog("ENTERED") connection = pika.BlockingConnection(pika.ConnectionParameters(host

Getting “pika.exceptions.ConnectionClosed” error while using rabbitmq in python

元气小坏坏 提交于 2019-12-07 09:36:40
问题 I am using "hello world" tutorial in :http://www.rabbitmq.com/tutorials/tutorial-two-python.html . worker.py looks like this import pika import time connection = pika.BlockingConnection(pika.ConnectionParameters( host='localhost')) channel = connection.channel() channel.queue_declare(queue='task_queue', durable=True) print ' [*] Waiting for messages. To exit press CTRL+C' def callback(ch, method, properties, body): print " [x] Received %r" % (body,) time.sleep( body.count('.') ) print " [x]

rabbitMQ交换机的发布订阅模式

筅森魡賤 提交于 2019-12-07 00:12:29
生产者: # !/usr/bin/env python # -*- coding: utf-8 -*- import pika # 创建连接对象 connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() # 创建交换机 channel.exchange_declare(exchange='logs', exchange_type='fanout') # 往队列里插入数据 channel.basic_publish(exchange='logs', routing_key='', body="I don't know") connection.close()    消费者: # !/usr/bin/env python # -*- coding: utf-8 -*- import pika # 创建连接对象 connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() # 创建交换机 channel.exchange_declare(exchange=

rabbitMQ 的简单模式

筅森魡賤 提交于 2019-12-06 23:33:27
生产者: # !/usr/bin/env python # -*- coding: utf-8 -*- import pika # 创建连接对象 connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) # 获取频道对象 channel = connection.channel() # 创建队列 channel.queue_declare(queue='hello') # 向队列插入数据 channel.basic_publish(exchange='', routing_key='hello', body='Hello 12334!') print("[x] Sent '生产者发送消息'") connection.close()    消费者: # !/usr/bin/env python # -*- coding: utf-8 -*- import pika connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() # 声明队列 channel.queue_declare(queue='hello') def