假设我有以下情况
producer sends the following instructions on to kafka :
1. "debit 100 from account A"
2. "send email to user A that his account is debited by 100"
and there is a consumer that does the following :
1. does the actual work of 'debit 100'
2. does the actual work of 'sending mail'
说,消费者实例崩溃,我提出了另一个实例。 现在,消费者告诉kafka'重播'(实现其数据视图) 就现实世界而言,消费者不应该按照这些指令行事(这将导致不需要借记和发送电子邮件),但是,只需阅读数据并做任何事情来实现其观点。
问题是,消费者如何知道它早先对某条消息采取了“行动”,因此,不应该重新采取行动。它只需要在内部捕获消息状态信息吗?
答案 0 :(得分:2)
您可以做的一件事是让您的消费者手动提交抵消。为此,您需要将默认消费者配置enable.auto.commit
从true
更改为false
。然后,在您的使用者应用程序中,在您成功处理消息后,您将提交偏移量。