2
votes

We are migrating a monolithic to a more distributed and we decided to use AxonFramework.

In Axon, as messages are first-class citizens, you get to model them as POJOs.

Now I wonder, since one event can be dispatched by one service and listen on any others, how should we handle event distribution.

My first impulse is to package them in a separate project as a JAR file, but this goes against a rule for microservices, that they should not share implementations.

Any suggestion is welcome.

2

2 Answers

5
votes

Having some form of 'common' module is definitely not uncommon, although I'd personally use that 'common' module for that specific application alone.

I'd generally say you should regard your commands/events/queries as the API of your application. As such, it might be beneficial to share the event structure with other projects, but just not the actual POJO itself. You could for example think about using ProtoBuf for this use case, were in ProtoBuf describes a schema for your events.

Another thing to think about is to not expose your whole 'event-API'. Typically you'll have quite some fine grained events, things which other (micro) services in your environment are not interested in. There are however always a couple of 'very important events', differently put 'milestone events', which others definitely are interested in. These milestone events in some scenarios aren't a direct POJO following from your domain, but rather an accumulations of several events.

It is thus not to uncommon to have a service which accumulates these and publishes another event to notify other services. The accumulating of these fine grained, internal events, and publishing a milestone event as a response to these is typically better suited as the event-API within your micro service architecture.

So that's a couple of ideas there for you, hope they give you some insights. I'd like to give a clear cut solution to your question, but such an answer always hides behind 'it depends'.

3
votes

You are right, the "official" rule is not to share models. So if you have distributed dev-teams, I would stick to it.

However, I tend to not follow strictly when I have components that are decoupled but developed by the same team or teams with high interaction ...