52

rabbitmq サーバーを実行し続ける時間が長ければ長いほど、未確認メッセージの問題が発生するようです。私はそれらを再び待ち行列に入れたいと思っています。実際、これを行う amqp コマンドがあるようですが、接続が使用しているチャネルにのみ適用されます。少なくとも試してみるために小さな pika スクリプトを作成しましたが、何かが足りないか、この方法では実行できません (rabbitmqctl ではどうですか?)

import pika

credentials = pika.PlainCredentials('***', '***')
parameters = pika.ConnectionParameters(host='localhost',port=5672,\
    credentials=credentials, virtual_host='***')

def handle_delivery(body):
    """Called when we receive a message from RabbitMQ"""
    print body

def on_connected(connection):
    """Called when we are fully connected to RabbitMQ"""
    connection.channel(on_channel_open)    

def on_channel_open(new_channel):
    """Called when our channel has opened"""
    global channel
    channel = new_channel
    channel.basic_recover(callback=handle_delivery,requeue=True)    

try:
    connection = pika.SelectConnection(parameters=parameters,\
        on_open_callback=on_connected)    

    # Loop so we can communicate with RabbitMQ
    connection.ioloop.start()
except KeyboardInterrupt:
    # Gracefully close the connection
    connection.close()
    # Loop until we're fully closed, will stop on its own
    connection.ioloop.start()
4

3 に答える 3