jeudi 5 octobre 2023

Is Outbox Pattern necessary in sycnchronous API call

Suppose I have an API endpoint which calls directly to this service.

class MockService {
   private final SomeRepository someRepository;
   private final MessageBroker messageBroker;

   @Transactional(rollbackFor = { SomeRelatedException.class })
   public void sendReq() {
      Data data = new Data();

      someRepository.save(data);

      messageBroker.publish(new Message(data));
   }
}

I wonder if outbox pattern is still necessary here because in case of message broker failure Spring will automatically rollback the transaction so the data will never save to the db and the user will get the response code like 50x error and so on.

Aucun commentaire:

Enregistrer un commentaire