Axon Event Handler not executing on a different microservice - spring-boot

I'm using CQRS with axon Framework in a project,and I'm using Kafka like evnt bus and MongoDB like event store
I have two Microservices, One for the Command Side and the Other for Query Side.
In the Query side I'm try using MySQL database for storing aggregates events, but the eventHandler does not work and I don Know why.
Command Microservice
Query Microservice

Could you share the configuration of the event handler? Or maybe some kind of error you are getting? Could be a lot of things. Might be because you use MySQL and Spring Boot, it actually trying to use MySQL as event store, and not MongoDB.

Related

Kafka as event source when using Axon

I'm studying Axon framework to try to use it in one of my microservices. I use Spring boot as my microservice and I want to use Axon framewrok for DDD and event sourcing. The thing is we already use Kafka in production and I'm not sure I can add another service (Axon serve) since it might consume resources I don't have (does it consume a lot of resources by the way?)
So I was thinking to use Kafka as event source and event routing with Axon.
Is it possible?
You can use Kafka as event bus using the Kafka extension for Axon. You can't use Kafka as event store however. So you still need Axon Server or a relational database for the event store to use Axon Framework.
You could also combine those, e.g. have some events via Kafka, and some via Axon Server.

Axon Event Handler not working on a different microservice

I was implementing event-driven CQRS concept using Axon framework. I created two separate microservices and their own two write and read databases.
I am publishing an event in ms-1 and now I want to handle that event in ms-2, so that I can persist it in my read DB. But the #EventHandler is not working in my ms-2. The events are published on the AxonServer, I can see the updates there.
And yes, I do have #Component on the EventHandler class in ms-2. Also, I am running AxonServer on docker.
The #EventHandler works fine when it is in the same microservice.
My axon-framework dependency is 4.5.8 and google guava's is 30.1.1-jre

AxonIQ AxonFramework MongoEventStorageEngine framework table creation on business DB

I am using AxonIQ AxonFramework version 4.5.3 with Spring Boot and custom event store.
I'm using MongoEventStorageEngine and configured a separate MongoDB database for the EventStorage.
I am doing some business logic with my business database through a microservice. In the same microservice, I've configured the custom EventStorage.
But a few tables (viz. association_value_entry, saga_entry, token_entry) are getting created on my business database which is a PostgresDB.
Why is AxonFramework creating new tables in my business database as I have already configured a separate MongoDB database for EventStorage. All the related database objects for Axon to work should be ideally created in the EventStorage database rather than in my business database.
The tables you are mentioned should be part of your 'read' model (I believe that is what you called business database).
They are not used for Event Storage or Event Sourcing but rather to specific things that are controlled on client side. For example, token_entry, among other things, is the table where your app keep track of the tokens and events it already consumed - you can read more about it here. Similar to the saga tables, where Sagas are stored on the client side having nothing to do with the Event Store - you can read more about it here.

Should microservices connected with axon share the axon framework related tables?

I am starting a project where I want to have multiple services that communicate with each other using the axon server.
I have more than one service with the following stack:
Spring Boot 2.3.0.RELEASE (with starters: Data, JPA, web, mysql)
Axon
Spring Boot Starter - 4.2.1
Each one of the services uses different schemas in the mysql server.
When I start the spring boot service with the axon framework activated, some tables for tokens, sagas, etc are created in the database schema of each application.
I have two questions
In the architecture that I am trying to build, should I have only
one database for all the ‘axon enabled’ services, so the sagas,
tokens, events, etc are only in one place?
If so, can anyone
provide an example of how to configure a custom
EntityManagerProvider to have the database of the service separated
from the database of Axon?
I assume each of your microservices models a sub-domain. Since the events do model a (sub)domain, along with aggregates, entities and value objects, I very much favor keeping the Axon-related schemas separated, most likely along with the databases/schemas corresponding to each service. I would, thus, prefer a modeling-first approach when considering such technical options.
It is what we're currently doing in our microservices ecosystem.
There is at least one more technical reason to go with the same schema (one per sub-domain, that is), both for Axon assets and application-specific assets. It was pointed out to me by my colleague Marian. If you (will) use Event Sourcing (thus reconstructing the state of an aggregate by fetching and applying all past events resulted after handling the commands) then you will, most likely, need transactions which encompass this fetching as well as the command handling code which might, in turn, trigger (through events) writes to your microservice-specific database.
Axon can require five tables, depending on your usages of Axon of course.
These are:
The Event table.
The Snapshot Event table.
The Token table.
The Saga table.
The Association Value Entry table.
When using Axon Server, tables 1 and 2 will not be created since Axon Server is the storage solution for events and snapshots.
When not using Axon Server, I would indeed suggest to have a dedicated datasource for these.
Table 3 which services the TokenStore, should be as close as possible to your Query Models. The tokens portray how far a given EventProcessor is with handling events. As these EventProcessors typically service projectors which create your query models, keeping them together is sensible from a transactional perspective.
Table 4 and 5 are both required for Sagas. The "Saga table" stores the serialized sagas, whereas the "Association Value Entry table" carries the associations values between events and sagas so that the framework can load the right sagas. I'd store these either in a dedicated database or along with the other tables of the given (micro)service.

Spring Cloud Stream - query topic without consuming a KTable/KStream explicitly?

I'm using Spring Cloud Stream library in a Java application. I want to use the Kafka Streams binder for a state store. The application will post messages to a topic, and I wish to use the Kafka Streams InteractiveQueryService to retrieve data from the same topic. Is it possible to perform such queries as-is, or do I need to first consume the topic as a KTable/KStream and materialize it before I can perform queries? I don't have any requirement to perform KTable/KStream processing on the topic, I just want to query the topic contents. I'm hoping there is some way to implicitly materialize it as a state store.
Interactive Queries is a feature that allows you to query client side state states. It's not a feature that allows you to query topics.
Hence, if you have data in a topic that you want to query it using "Interactive Queries", you need to load the data into a state store within Kafka Streams.

Resources