0

I need different messages to be sent to the queue - each by its personal schedule. So I have message list and related interval to resend each one. I use rabbitMQ/pika and apscheduler. According to numerous examples, I created the simplest BlockingConnection/channel/queue. When immediately after that I try to push messages - everything works fine, I can see in rabbitmq web-interface that all the messages become in the queue. Here is the piece of code that works:

    self.cr = Queue('DIRECT_C_QUEUE', True, ex_type='direct')
    for i in range(1,10000):
        self.cr.channel.basic_publish(exchange='', routing_key='DIRECT_C_QUEUE', body='hello_world')

But if I try to push messages (in exactly same way) via apscheduler callback function - only few (about 1-10) messages appear in the queue (but callbacks are fired all the time and there are no any exception when publishing message!).

Finally I begin to receive such warnings:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pika/connection.py:642: UserWarning: Pika: Write buffer exceeded warning threshold at 1125 bytes and an estimated 43 frames behind warn(message % (self.outbound_buffer.size, est_frames_behind))

and still no new messages in the queue.

I am new in python, any help is much appreciate.

4

2 回答 2

2

我找到了问题的根源:apscheduler 在单独的线程中运行basic_publish调用,而 pika 不建议在线程之间共享连接 - http://pika.github.com/faq.html

所以我可以选择每次创建新连接,或者将新消息放入某个队列并从主线程(创建连接的位置)发布它们。

于 2012-08-08T07:50:04.773 回答
-1

我通过增加 ulimit 解决了这个问题

编辑 /etc/default/rabbitmq-server 并设置

ulimit -n 4096

然后重启rabbitmq

sudo /etc/init.d/rabbitmq-server 重启

于 2012-07-17T16:04:25.940 回答