1
votes

I'm trying to realize a simple distributed applications, and I would like to save all the events into the event store. For this reason, as suggested in the "documentation" of Axon here, I would like to use Mysql as event store.

Since I haven't very much experience with Spring, I cannot understand how to getting it working. I would have two separate services one for the command side and one for the query side. Since I'm planning to have more services, I would like to know how to configure them to use an external event store (not stored inside of any of these services).

For the distribution of the commands and events, I'm using RabbitMQ:

@Bean
public org.springframework.amqp.core.Exchange exchange() {
    return ExchangeBuilder.fanoutExchange("AxonEvents").build();
}

@Bean
public Queue queue() {
    return QueueBuilder.durable("AxonEvents").build();
}

@Bean
public Binding binding() {
    return BindingBuilder.bind(queue()).to(exchange()).with("*").noargs();
}


@Autowired
public void configure(AmqpAdmin admin)
{
    admin.declareExchange(exchange());
    admin.declareQueue(queue());
    admin.declareBinding(binding());
}

This creates the required queue on a local running RabbitMQ instance (with default username and password).

My question is: How can I configure Axon to use mysql as an event store?

1

1 Answers

1
votes

As the Reference Guide currently does not specify this, I am gonna point this out here. Currently you've roughly got two approaches you follow when distributing an Axon application or separating an Axon application into (micro) services:

  1. Use an full open source approach
  2. Use AxonHub / AxonDb

Taking approach 2, which you can do in a developer environment, you would only have to run AxonHub and AxonDb and configure them to your application. That's it, your done; you can scale out your application and all the messages are routed as desired.

If you want to take route 1 however, you will have to provide several configurations

Firstly, you state you use RabbitMQ to route commands and events. In fact, the framework does not simply allow using RabbitMQ to route commands at all. Do note it is a solution to distribute EventMessages, just not CommandMessages. I suggest either using JGroups or Spring Cloud to route your commands in a open-source scenario (I have added links to the Reference Guide pages regarding distributing the CommandBus for JGroups and Spring Cloud).

To distribute your events, you can take three approaches:

  1. Use a shared database for your events.
  2. Use AMQP to send your evens to different instances.
  3. Use Kafka to send your evens to different instances.

My personal preference when starting an application though, is to begin with one monolith and separate when necessary. I think the term 'Evolutionary Micro Services' catches this nicely.

Any how, if you use the messaging paradigm supported by Axon to it's fullest, splitting out the Command side from the Query side after wards should be quite simple. If you'd in addition use the AxonHub to distribute your messages, then you are practically done.

Concluding though, I did not find a very exact request from your issues. Does this give you the required information to proceed, @Federico Ponzi?

Update

After having given it some thought, I think your solution is quite simple. You are using Spring Boot and you want to set up your EventStore to use MySQL. For Axon to set the right EventStorageEngine (the infra component used under the covers to read/write events), you can simply add a dependency on the spring-boot-starter-data-jpa. Axon it's auto configuration will in that scenario automatically notice that you have Spring Data JPA on your classpath, and as such will set the JpaEventStorageEngine.