Spring Kafka是Acknowledgement.acknowledge线程安全的吗? [英] Spring Kafka is Acknowledgement.acknowledge thread safe?
问题描述
我正在实现一个基于kafka的应用程序,我想在其中手动确认传入的消息.架构迫使我在单独的线程中执行此操作.
I am implementing an kafka based application where I would like to manually acknowledge incoming messages. Architecture forces me to do it in a separate thread.
问题是:在与使用者不同的线程中执行Acknowledgement.acknowledge()是否可能和安全?
推荐答案
是的,只要您使用 MANUAL
而不是 MANUAL_IMMEDIATE
,但我不会认为您会得到期望的结果.
Yes it is, as long as you use MANUAL
and not MANUAL_IMMEDIATE
, but I don't think you'll get what you expect.
Kafka不会跟踪每条消息,只是跟踪分区中的偏移量.
Kafka doesn't track each message, just offsets within the partition.
比方说,消息1到达后,您将移交给另一个线程.然后消息2到达并将其传递到另一个线程.
Let's say message 1 arrives and you hand off to another thread. Then message 2 arrives and it is handed off to yet another thread.
确认消息2的偏移量后,您实际上就是在确认这两个消息.
When the offset for message 2 is ack'd, you are effectively acking both messages.
这篇关于Spring Kafka是Acknowledgement.acknowledge线程安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!