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屋!