Problems with registered interceptors.

Hi,

I have 2 problems when using interceptors.

I have one service where everything works like expected, command, events and queries are intercepted and I can add some generic data to it.

In the other service I have I have 2 problems:

  1. Events which are send out if an Aggregate with apply are not intercepted. I use the following way to register the interceptor:
@Bean
public EventGateway eventGateway(EventBus eventBus) {
    return DefaultEventGateway.builder()
        .eventBus(eventBus)
        .dispatchInterceptors(new LocaleEventDispatchInterceptor())
        .build();
}
  1. When adding a query interceptor by
@Bean
public QueryBus configureQueryBus() {
    QueryBus queryBus = SimpleQueryBus.builder().build();
    queryBus.registerDispatchInterceptor(new LocaleQueryDispatchInterceptor());
    return queryBus;
}

Normal queries queryGateway.query( work like expected.
Subsription queries we use with queryGateway.subscriptionQuery(
throw a timeout exception now.

Any idea how to register this properly? For queries unfortunately the documentation on the website is very limited…

If would be great if you post an example here.

Best Regards,
Michael

Hey Michael,

  1. Try registering the dispatching interceptor directly on EventBus instead of EventGateway.
  2. Didn’t understand a second issue, but if you are trying to apply the interceptor to subscription query, this is possible with latest Axon Framework release: 4.4.1

Hope this helps,
Stefan

Hi Stefan,

  1. I thought I tried this already with no success. I can give it a 2nd try.

  2. The 2nd one is the major problem. If I register like described my normal query works.
    BUT the subscription queries do then all timeout. I don’t need the interceptor at subscription queries as this is only the “return” value.
    I need to pass my additional data for normal queries only. Is there a way to register the interceptor only for normal queries and not for subscription queries?

Best Regards,
Michael

Hi Stefan

I tried to use the https://docs.axoniq.io/reference-guide/configuring-infrastructure-components/messaging-concepts/message-intercepting

public EventBus configureEventBus(EventStorageEngine eventStorageEngine) {
    // note that an EventStore is a more specific implementation of an EventBus
    EventBus eventBus = EmbeddedEventStore.builder()
        .storageEngine(eventStorageEngine)
        .build();
    eventBus.registerDispatchInterceptor(new LocaleEventDispatchInterceptor());
    return eventBus;
}

example. If I add a @Bean there I only get a

Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ‘org.axonframework.eventhandling.EventBus’ available: expected single matching bean but found 2: configureEventBus,eventStore

I think it is a really simple fix. I simply don’t see it right now…

You know what is wrong?

Cheers, Michael

Hi,

If I add a @Primary I get:

The following candidates were found but could not be injected:

  • Bean method ‘eventStorageEngine’ in ‘JdbcAutoConfiguration’ not loaded because @ConditionalOnMissingBean (types: org.axonframework.eventsourcing.eventstore.EventStorageEngine,org.axonframework.eventhandling.EventBus; SearchStrategy: all) found beans of type ‘org.axonframework.eventhandling.EventBus’ eventStore, configureEventBus
  • Bean method ‘eventStorageEngine’ in ‘JpaEventStoreAutoConfiguration’ not loaded because @ConditionalOnMissingBean (types: org.axonframework.eventsourcing.eventstore.EventStorageEngine,org.axonframework.eventhandling.EventBus; SearchStrategy: all) found beans of type ‘org.axonframework.eventhandling.EventBus’ eventStore, configureEventBus

Hi Michael,

Didn’t do deep dive into our configuration but I think that you have overridden some default configuration and that’s why it’s failing.

I tried this code, and it works, sub queries work fine, and all events are logged.

@Autowired
public void registerQueryInterceptors(QueryBus queryBus) {
queryBus.registerHandlerInterceptor(new LoggingInterceptor<>());
}

@Autowired
public void registerEventInterceptors(EventBus eventBus) {
eventBus.registerDispatchInterceptor(new LoggingInterceptor<>());
}

With @autowired I’m getting already configured event & query bus and attaching additional configuration.
Can you try this and see if it helps?

Best,
Stefan

Hi Stefan,

great. Much easier like this.

I use
queryBus.registerDispatchInterceptor

instead of
queryBus.registerHandlerInterceptor(new LoggingInterceptor<>());

But now it works fine. Thanks a lot…

Cheers, Michael

Great!

Glad it helps.

Cheers,
Stefan

the only thing which is not intercepted are the EventsourcingHandlers. But there I don’t need it. I use it to pass the current locale around.

Cheers, Michael