What is a messageMonitor and its purpose?

In the AxonAutoConfiguration.java file there are many times where a builder to a component calls a messageMonitor:

L224: .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore"))
L244: .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore"))
L372: .messageMonitor(axonConfiguration.messageMonitor(CommandBus.class, "commandBus"))
L385: .messageMonitor(axonConfiguration.messageMonitor(QueryBus.class, "queryBus"))
L398: .updateMessageMonitor(configuration.messageMonitor(QueryUpdateEmitter.class, "queryUpdateEmitter"))

I’m wondering if someone can please clarify (from a high level) what exactly a message monitor is and how it is used in the framework? What do the above calls to messageMonitor achieve?

Thanks!

I can most definitely share some information about that, @vab2048!
Axon Framework uses a MessageMonitor on any component processing messages.
Thus, the CommandBus, EventBus, QueryBus, etc contain a MessageMonitor component.
Every infrastructure component uses the MessageMonitor to monitor a Message at key moments in its lifecycle.
Moments like “invocation,” “success,” “failure,” and “ignored.”

If the user has not configured a metric registry, the NoopMessageMonitor is set.
By adding axon-metrics or axon-micrometer you can include Dropwizard Metrics or Micrometer respectively as the MessageMonitor implementation.
In a Spring Boot environment simply adding the dependency is sufficient.

Both solution will register the metrics to their respective registry allowing further monitoring of an Axon-based system.
If you’re interested you can find the documentation on the subject here.

1 Like