Java config for eventprocessors

Hi,

For our project we or stepping away from yml configuration for the eventprocessor and are going to java configuration.

We are however seeing that our autoconfigure method is executed in the middle of the axon configuration giving us errors like

`

Caused by: java.lang.IllegalArgumentException: A metric named someProcessor.capacity.capacity already exists
at com.codahale.metrics.MetricRegistry.register(MetricRegistry.java:97) ~[metrics-core-4.0.5.jar:4.0.5]
at com.codahale.metrics.MetricRegistry.registerAll(MetricRegistry.java:509) ~[metrics-core-4.0.5.jar:4.0.5]
at com.codahale.metrics.MetricRegistry.register(MetricRegistry.java:91) ~[metrics-core-4.0.5.jar:4.0.5]
at org.axonframework.metrics.GlobalMetricRegistry.registerEventProcessor(GlobalMetricRegistry.java:128) ~[axon-metrics-4.1.1.jar:4.1.1]
at org.axonframework.metrics.GlobalMetricRegistry.registerComponent(GlobalMetricRegistry.java:93) ~[axon-metrics-4.1.1.jar:4.1.1]
at org.axonframework.metrics.GlobalMetricRegistry.lambda$null$0(GlobalMetricRegistry.java:77) ~[axon-metrics-4.1.1.jar:4.1.1]
at org.axonframework.config.DefaultConfigurer.lambda$configureMessageMonitor$13(DefaultConfigurer.java:403) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.MessageMonitorFactoryBuilder.lambda$build$9(MessageMonitorFactoryBuilder.java:89) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.messageMonitor(DefaultConfigurer.java:664) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.spring.config.AxonConfiguration.messageMonitor(AxonConfiguration.java:153) ~[axon-spring-4.1.1.jar:4.1.1]
at org.axonframework.config.EventProcessingModule.messageMonitor(EventProcessingModule.java:360) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.EventProcessingModule.subscribingEventProcessor(EventProcessingModule.java:637) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.EventProcessingModule.lambda$usingSubscribingEventProcessors$50(EventProcessingModule.java:480) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.EventProcessingModule.buildEventProcessor(EventProcessingModule.java:253) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.EventProcessingModule.lambda$null$25(EventProcessingModule.java:175) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.Component.get(Component.java:73) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.EventProcessingModule.lambda$start$27(EventProcessingModule.java:182) ~[axon-configuration-4.1.1.jar:4.1.1]
at java.base/java.util.HashMap.forEach(HashMap.java:1336) ~[na:na]
at org.axonframework.config.EventProcessingModule.start(EventProcessingModule.java:182) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.spring.config.SpringAxonAutoConfigurer$LazyRetrievedModuleConfiguration.start(SpringAxonAutoConfigurer.java:462) ~[axon-spring-4.1.1.jar:4.1.1]
at org.axonframework.config.DefaultConfigurer$RunnableHandler.run(DefaultConfigurer.java:636) ~[axon-configuration-4.1.1.jar:4.1.1]
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[na:na]
at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[na:na]
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) ~[na:na]
at org.axonframework.config.DefaultConfigurer.invokeStartHandlers(DefaultConfigurer.java:571) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.start(DefaultConfigurer.java:679) ~[axon-configuration-4.1.1.jar:4.1.1]
at org.axonframework.spring.config.AxonConfiguration.start(AxonConfiguration.java:198) ~[axon-spring-4.1.1.jar:4.1.1]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]

`

The style of confugration we use is:

`

@Configuration
public class SomeExampleConfiguration {

@Autowired
public void configureSomeEventProcessors(EventProcessingConfigurer eventProcessingConfigurer,
EventStore eventStore,
TokenStore tokenStore) {
eventProcessingConfigurer.registerTrackingEventProcessor(“someProcessor”,
messageSource -> eventStore,
c -> TrackingEventProcessorConfiguration.forParallelProcessing(2));
eventProcessingConfigurer.registerSequencingPolicy(“someProcessor”, policy -> new FullConcurrencyPolicy());
eventProcessingConfigurer.registerMessageMonitor(“someProcessor”, configuration -> NoOpMessageMonitor.instance());
eventProcessingConfigurer.registerTokenStore(“someProcessor”, configuration -> tokenStore);
eventProcessingConfigurer.registerHandlerInterceptor(“someProcessor”, configuration -> new SomeInterceptor());
eventProcessingConfigurer.registerHandlerInterceptor(“someProcessor”, configuration -> new SomeOtherInterceptor());
eventProcessingConfigurer.registerListenerInvocationErrorHandler(“someProcessor”, configuration -> new SomeErrorHandler());
}
}

`

We would have multiple methods like this spread out over different articacts.

Are we doing something wrong? Is there maybe a lifecycle hook or something we can use?

Kind regards,

Tom.

Hi Tom,

the exception suggests that 2 components called “someProcessor” try to create the same monitors. Given your Java configuration, it suggests that you don’t event want to enable monitoring, as you explicitly configure the NoOpMessageMonitor.

To really find out what’s happening, I would need to see the entire (processor related) configuration. An attempt to reproduce locally failed, in the sense that it works as expected.

One quick thing you could try is to update your dependencies to Axon 4.2, just to make sure it hasn’t been addressed in that version. Lastly, I would suggest putting a breakpoint in the EventProcessingModule#trackingEventProcessor method (line 661 in Axon 4.2). Inside that method, the actual TrackingProcessor instance is created. Another point of interest is the EventProcessingModule#messageMonitor method, which retrieves the actual monitor configured for the processor.

Hope this helps.
Cheers,

twitter-icon_128x128.png

Thanks for the reply!

After debugging a lot more we found that it was our own fault.

We have a rather complicated setup with an internal eventstore, axondb and axonserver. The last one currently only used for queries.
To create our QueryBus we injected the AxonConfiguration class.
This worked unitl we did a development where we needed the QueryUpdateEmitter. This triggered and eager initialization of the queryBus which in turn triggered the initialization of the AconConfiguration class which broke stuff.

We removed the depependency on AxonConfiguration for the creation of our QueryBus and now it is working as expected.

On a side note, yes we do have plans to migrate axondb to axonserver to simplify the setup :wink:

Good to hear you found it!

twitter-icon_128x128.png