Rabbitmq kombu消费者队列在一段时间后失去绑定到Exchange

时间:2014-04-07 14:22:37

标签: python rabbitmq kombu

我的Kombu创建了一个奇怪的问题队列。过了一段时间,他们就停止收到消息。没有错误,但不再收到消息。当我取消绑定队列(从rabbitmq web界面)并将其重新绑定到相同的交换和路由键时,一切都在重新运行一段时间......然后再次。

我在这里错过了什么?我很乐意为此提供帮助。 我想也许我应该添加心跳?别的什么?

这是侦听器用来创建队列并监听它的类:

class UpdaterMixin(object):
    #  binding management commands to event names
    #  override in subclass
    event_handlers = {}
    app_name = ''   #override in subclass

    def __init__(self):
        if not self.app_name or len(self.event_handlers) == 0:
            print('app_name or event_handlers arent implemented')
            raise NotImplementedError()
        else:
            self.connection_url = settings.BROKER_URL
            self.exchange_name = settings.BUS_SETTINGS['exchange_name']
            self.exchange_type = settings.BUS_SETTINGS['exchange_type']
            self.routing_key = settings.ROUTING_KEYS[self.app_name]

    def start_listener(self):
        logger.info('started %s updater listener' % self.app_name)\\
        with Connection(self.connection_url) as connection:
            exchange = Exchange(self.exchange_name, self.exchange_type, durable=True)
            queue = Queue('%s_updater' % self.app_name, exchange=exchange, routing_key=self.routing_key)
            with connection.Consumer(queue, callbacks=[self.process_message]) as consumer:
                while True:
                    logger.info('Consuming events')
                    connection.drain_events()

    def process_message(self, body, message):


        logger.info('data received: %s' % body)
        handler = self.event_handlers[body['event']]
        logger.info('Executing management command: %s' % str(handler))
        handler(body)
        message.ack()

Rabbitmq版本:3.2

0 个答案:

没有答案