兔皮卡。如何解决这个问题

2024-05-29 02:07:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用pika python库与RabbitMQ消息代理进行交互

要创建连接,我使用:

def get_connection():
    credential = pika.PlainCredentials(LOGIN, PASS)
    parameters = pika.ConnectionParameters(
        HOST, 
        5672, 
        '/', 
        credential, 
        heartbeat=0,
        blocked_connection_timeout=0
    )
    connection = pika.BlockingConnection(parameters)
    return connection

进一步:

channel = get_connection().channel()
channel.basic_consume(queue='test', on_message_callback=run)
channel.start_consuming()

run函数执行长时间的计算(~30分钟),然后我调用ch.basic_ack(method.delivery_tag),但我得到错误: StreamLostError: Stream connection lost: ConnectionResetError(104, 'Connection reset by peer')

我不知道我需要做什么来避免这个错误。我更改了心跳参数的值,但没有任何帮助


Tags: run消息代理getbasicdef错误channel

热门问题