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
Add a comment  | 

1 Answer 1

Reset to default 0

While 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