Python 消费者(通过 pika)中使用的 RabbitMQ 能否在并发接收的消息之间存在竞争条件?
Can RabbitMQ used in a Python consumer (via pika) have race conditions between concurrently received messages?
假设我们在 Python 中有以下简单的 RabbitMQ 回调逻辑:
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password")))
channel = connection.channel()
msg_count = 0
def callback(ch, method, properties, body):
global msg_count
msg_count += 1
print("Received %i messages" % msg_count)
channel.basic_consume(queue="my_queue", on_message_callback=callback, auto_ack=True)
如果生产者实际上同时发送两条消息,是否有可能由于竞争条件而将“Received 1 messages”打印两次?
我只是不确定这些回调如何 运行 - 它们 运行 是同时发生的吗?在线程中?其他方式?
If a producer sends two messages practically at the same time, is it
possible that "Received 1 messages" will be printed twice due to a
race condition?
没有。 Pika 在内部运行一个 I/O 循环,事件在准备就绪时按顺序处理。
FWIW 目前我是 Pika 的主要维护者。
注意: RabbitMQ 团队监控 rabbitmq-users
mailing list 并且有时只在 Whosebug 上回答问题。
假设我们在 Python 中有以下简单的 RabbitMQ 回调逻辑:
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password")))
channel = connection.channel()
msg_count = 0
def callback(ch, method, properties, body):
global msg_count
msg_count += 1
print("Received %i messages" % msg_count)
channel.basic_consume(queue="my_queue", on_message_callback=callback, auto_ack=True)
如果生产者实际上同时发送两条消息,是否有可能由于竞争条件而将“Received 1 messages”打印两次?
我只是不确定这些回调如何 运行 - 它们 运行 是同时发生的吗?在线程中?其他方式?
If a producer sends two messages practically at the same time, is it possible that "Received 1 messages" will be printed twice due to a race condition?
没有。 Pika 在内部运行一个 I/O 循环,事件在准备就绪时按顺序处理。
FWIW 目前我是 Pika 的主要维护者。
注意: RabbitMQ 团队监控 rabbitmq-users
mailing list 并且有时只在 Whosebug 上回答问题。