春季kafka与春季JPA
我有两个微型服务A和B。
一项服务正在向Kafka主题“ A-Topic”发送消息。 B服务正在消耗消息。
在B服务中,Kafka侦听器将执行以下步骤,
1. Persist the data in the database (repo.save(entity))
2. Publish the response message to "B-Topic". (kafkatemplte.send("B-Topic",message))
我正在使用Spring @Transactional注释在两个服务中的服务级别。
在成功情况下,数据正在持续存在,并且成功消息仅发布给该主题一次
,因为
在失败方案中,由于完整性约束违规问题,数据库保存失败了。在这种情况下,失败消息将连续发布10次。
如果我从服务类中删除交易注释,则在失败方案中仅发布一次消息。
我不明白,交易注释是如何导致向Kafka发布10次消息的消息。
请让我知道您的意见。
提前致谢。
I have two micro services A and B.
A service is sending message to Kafka topic "A-Topic". B service is consuming the message.
In the B service, kafka listener will do the below steps
1. Persist the data in the database (repo.save(entity))
2. Publish the response message to "B-Topic". (kafkatemplte.send("B-Topic",message))
I am using the Spring @Transactional annotation at the service level in both services.
In the success scenario, data is getting persisted and success message is published to the topic only once
where as
in the Failure scenario, database save was failed due to integrity constraint violation issue. In this case, failure message is published to the Kafka 10 times continuously.
If I remove Transactional annotation from the service class then the message is published only once in failure scenario also.
I don't understand, how come transactional annotation is causing the message to be published 10 times to kafka.
Please let me know your inputs.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认错误处理程序将尝试交付10次;您需要在侦听器容器中启用KAFKA交易,以便将KAFKA发送的发送(以及
b-Topic
需要 code> simelationsimalation.level = read_comment
)。https:// https:// https://docsring.io.io/spring.io/spring-kafka /doc/current/reference/html/#交易
The default error handler will attempt delivery 10 times; you need to enable Kafka transactions in the listener container so the kafka sends will be rolled back (and the consumer on
B-Topic
needsisolation.level=read_committed
).https://docs.spring.io/spring-kafka/docs/current/reference/html/#transactions