admin管理员组文章数量:1393054
Is it good practice to achive atomicity by following code.
I know 2 phase commit concept, outbox pattern. I don't want to use third party library like Atomiko.
@Transactional
Public void test transaction(){
try{
// Assume obj created here
myRepository.save(obj):
//is this ok to catch data base exception by below
entitimanger.flush():
//Produce message
Kafkatemplate.executeInTransaction(k->
{
K.send ("topic-1","msg"):
K.send ("topic-2","msg"):
K.send ("topic-3","msg"):
}):
}Catch(Exception e){
throw e;
}
}
Is it good practice to achive atomicity by following code.
I know 2 phase commit concept, outbox pattern. I don't want to use third party library like Atomiko.
@Transactional
Public void test transaction(){
try{
// Assume obj created here
myRepository.save(obj):
//is this ok to catch data base exception by below
entitimanger.flush():
//Produce message
Kafkatemplate.executeInTransaction(k->
{
K.send ("topic-1","msg"):
K.send ("topic-2","msg"):
K.send ("topic-3","msg"):
}):
}Catch(Exception e){
throw e;
}
}
Share
Improve this question
asked Mar 17 at 4:34
Altaf ShaikhAltaf Shaikh
511 silver badge7 bronze badges
1 Answer
Reset to default 0While the approach you shared would work, it has some downsides and is thus not followed in general by the industry.
Any call to test_transaction
method would require both the database and the Kafka brokers to be available. On the other hand, the outbox pattern decouples database and Kafka brokers to work independently.
I don't think there would be any reason to push to database and Kafka atomically, as any system using Kafka should rely on eventual consistency!
Therefore, I would suggest using outbox pattern here.
本文标签: Transaction management in both apache kafka and RDBMSStack Overflow
版权声明:本文标题:Transaction management in both apache kafka and RDBMS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744579373a2613826.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论