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)
@Bean
public TargetContextResolver<Message<?>> targetContextResolver(ContextNameResolver contextNameResolver) { ...}
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.
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?
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.