How to publish an event to another context

Hello AxonIQers,

I try to publish an event to a different context than the application’s context.
I tried to create a TargetContextResolver, but it does not get called when I issue a eventGateway.publish(event)

    public TargetContextResolver<Message<?>> targetContextResolver(ContextNameResolver contextNameResolver) { ...}

Hi @dbeaudry,

Indeed, a TargetContextResolver should do the trick as shown here:

You also have to make sure that the application has the correct rights to publish events to that context!


Bonjour Daniel,

Ça va?

The TargetContextResolver Bean is only invoked when using a command or query and is not when publishing an event. As @lfgcampos mentioned you need to assign the correct access rights.

Best regards,


Hi Daniel,

Lucas and I had a little discussion about this what could be the use case for handling a command in a certain context and applying the event in another instead of sending a command to the other context. Can you elaborate a little bit more on it?

Kind Regards


1 Like

In fact, the TargetContextResolver works realy well for commands and queries, but does not seems to be invoked when semding an event.

We want to achieve some sort of error collecting by sending an event to a “failuremgmt” context from within many of our applications. We do not want to polute those applications context with such messages. Therefore, we want to collect them separately.