Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Congratulations and question #4

Closed
frederikhors opened this issue Mar 30, 2023 · 7 comments
Closed

Congratulations and question #4

frederikhors opened this issue Mar 30, 2023 · 7 comments

Comments

@frederikhors
Copy link

Congratulations for your project.

Can I ask you how to deal with db transactions calls?

@jultabary
Copy link
Owner

Hi thanks 😄
You can implements your own CommandBus depending the framework you are using.
If you are in a SpringbootProjet : it can looks like something like this.

@Component
@Qualifier("transactionCommandBus")
public class TransactionCommandBus implements CommandBus {
         private CommandBus nextCommandBus;

         public TransactionCommandBus() {
         }
         
         @Transactionnal
         public List<Event> dispatch(Command command) {
                 return this.nextCommandBus.dispatch(command);
         }
         
         public void setNextCommandBus(CommandBus commandBus) {
                 this.nextCommandBus = commandBus;
         }
}

Then hen you will building the bus:

@Component
public class Application implements CommandBus, QueryBus {
       private CommandBus commandBus;
       private QueryBus queryBus;

       public Application(@Qualifier("transactionCommandBus") transactionCommandBus) {
            CommandBus commandDispatcher = new CommandDispatcher(.....);
            transactionCommandBus.setNextCommandBus(commandDispatcher);
            this.commandBus = transactionCommandBus;
            .....
      }

      public List<Event> dispatch(Command command) {
            return this.commandBus.dispatch(command);
      }
 
}

With a kind of commandBus like this all your "business" transaction (represents by CommandHandler) will be executed in a db transaction.

I will add an example in this repository.

@frederikhors
Copy link
Author

Thank you. I'm using Rust. It would be awesome to have an example in Rust. :) ♥

@jultabary
Copy link
Owner

Have a look here , i have updated this example with a new command_bus wich handle database transaction.

@jultabary
Copy link
Owner

By the way, it should better to wrap the persistence transaction middleware by the logging middleware. And not the opposite.
I will fix it later

@frederikhors
Copy link
Author

I will fix it later

Closed?

@jultabary
Copy link
Owner

jultabary commented Apr 6, 2023

Yes the sqlx rocket prject has been updated here.
Does it answer to your question 😄 ?

@jultabary jultabary reopened this Apr 6, 2023
@frederikhors
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants