@@ -166,30 +166,54 @@ Since all command processing is done in the same thread, this implementation is
166166{% tabs %}
167167{% tab title="Axon Configuration API" %}
168168``` java
169- Configurer configurer =
170- DefaultConfigurer . defaultConfiguration()
171- .configureCommandBus(
172- c - > SimpleCommandBus . builder()
173- .transactionManager(c. getComponent(TransactionManager . class))
174- .messageMonitor(c. messageMonitor(SimpleCommandBus . class, " commandBus" ))
175- .build()
176- );
169+ public class AxonConfig {
170+ // omitting other configuration methods...
171+ public void configureSimpleCommandBus (Configurer configurer ) {
172+ configurer. configureCommandBus(
173+ config - > {
174+ CommandBus commandBus =
175+ SimpleCommandBus . builder()
176+ .transactionManager(config. getComponent(TransactionManager . class))
177+ .spanFactory(config. spanFactory())
178+ .messageMonitor(config. messageMonitor(SimpleCommandBus . class, " commandBus" ))
179+ // ...
180+ .build();
181+ commandBus. registerHandlerInterceptor(
182+ new CorrelationDataInterceptor<> (config. correlationDataProviders())
183+ );
184+ return commandBus;
185+ }
186+ );
187+ }
188+ }
177189```
178190{% endtab %}
179191
180192{% tab title="Spring Boot AutoConfiguration" %}
181193``` java
182- @Bean
183- public SimpleCommandBus commandBus(TransactionManager txManager, AxonConfiguration axonConfiguration) {
184- SimpleCommandBus commandBus =
185- SimpleCommandBus . builder()
186- .transactionManager(txManager)
187- .messageMonitor(axonConfiguration. messageMonitor(CommandBus . class, " commandBus" ))
188- .build();
189- commandBus. registerHandlerInterceptor(
190- new CorrelationDataInterceptor<> (axonConfiguration. correlationDataProviders())
191- );
192- return commandBus;
194+ @Configuration
195+ public class AxonConfig {
196+ // omitting other configuration methods...
197+ @Bean
198+ public CommandBus simpleCommandBus (TransactionManager transactionManager ,
199+ GlobalMetricRegistry metricRegistry ,
200+ SpanFactory spanFactory ) {
201+ return SimpleCommandBus . builder()
202+ .transactionManager(transactionManager)
203+ .messageMonitor(metricRegistry. registerCommandBus(" commandBus" ))
204+ .spanFactory(spanFactory)
205+ // ...
206+ .build();
207+ }
208+
209+ @Bean
210+ public ConfigurerModule commandBusCorrelationConfigurerModule () {
211+ return configurer - > configurer. onInitialize(
212+ config - > config. commandBus(). registerHandlerInterceptor(
213+ new CorrelationDataInterceptor<> (config. correlationDataProviders())
214+ )
215+ );
216+ }
193217}
194218```
195219{% endtab %}
@@ -208,24 +232,56 @@ Note that the `AsynchronousCommandBus` should be shut down when stopping the app
208232{% tabs %}
209233{% tab title="Axon Configuration API" %}
210234``` java
211- Configurer configurer = DefaultConfigurer . defaultConfiguration()
212- .configureCommandBus(c - > AsynchronousCommandBus . builder(). transactionManager(c. getComponent(TransactionManager . class))
213- .messageMonitor(c. messageMonitor(AsynchronousCommandBus . class, " commandBus" ))
214- .build());
235+ public class AxonConfig {
236+ // omitting other configuration methods...
237+ public void configureAsynchronousCommandBus (Configurer configurer ) {
238+ configurer. configureCommandBus(
239+ config - > {
240+ CommandBus commandBus =
241+ AsynchronousCommandBus . builder()
242+ .transactionManager(config. getComponent(TransactionManager . class))
243+ .spanFactory(config. spanFactory())
244+ .messageMonitor(config. messageMonitor(
245+ AsynchronousCommandBus . class, " commandBus"
246+ ))
247+ // ...
248+ .build();
249+ commandBus. registerHandlerInterceptor(
250+ new CorrelationDataInterceptor<> (config. correlationDataProviders())
251+ );
252+ return commandBus;
253+ }
254+ );
255+ }
256+ }
215257```
216258{% endtab %}
217259
218260{% tab title="Spring Boot AutoConfiguration" %}
219261``` java
220- @Bean
221- public AsynchronousCommandBus commandBus(TransactionManager txManager, AxonConfiguration axonConfiguration) {
222- AsynchronousCommandBus commandBus =
223- AsynchronousCommandBus . builder()
224- .transactionManager(txManager)
225- .messageMonitor(axonConfiguration. messageMonitor(AsynchronousCommandBus . class, " commandBus" ))
226- .build();
227- commandBus. registerHandlerInterceptor(new CorrelationDataInterceptor<> (axonConfiguration. correlationDataProviders()));
228- return commandBus;
262+ @Configuration
263+ public class AxonConfig {
264+ // omitting other configuration methods...
265+ @Bean
266+ public CommandBus asynchronousCommandBus (TransactionManager transactionManager ,
267+ GlobalMetricRegistry metricRegistry ,
268+ SpanFactory spanFactory ) {
269+ return AsynchronousCommandBus . builder()
270+ .transactionManager(transactionManager)
271+ .messageMonitor(metricRegistry. registerCommandBus(" commandBus" ))
272+ .spanFactory(spanFactory)
273+ // ...
274+ .build();
275+ }
276+
277+ @Bean
278+ public ConfigurerModule commandBusCorrelationConfigurerModule () {
279+ return configurer - > configurer. onInitialize(
280+ config - > config. commandBus(). registerHandlerInterceptor(
281+ new CorrelationDataInterceptor<> (config. correlationDataProviders())
282+ )
283+ );
284+ }
229285}
230286```
231287{% endtab %}
@@ -349,28 +405,50 @@ Optionally, you can provide a `DisruptorConfiguration` instance, which allows yo
349405{% tabs %}
350406{% tab title="Axon Configuration API" %}
351407``` java
352- Configurer configurer = DefaultConfigurer . defaultConfiguration()
353- .configureCommandBus(c - >
354- DisruptorCommandBus . builder()
355- .transactionManager(c. getComponent(TransactionManager . class))
356- .messageMonitor(c. messageMonitor(DisruptorCommandBus . class, " commandBus" ))
357- .bufferSize(4096 )
358- .build()
359- );
408+ public class AxonConfig {
409+ // omitting other configuration methods...
410+ public void configureDisruptorCommandBus (Configurer configurer ) {
411+ configurer. configureCommandBus(config - > {
412+ CommandBus commandBus = DisruptorCommandBus . builder()
413+ .transactionManager(config. getComponent(TransactionManager . class))
414+ .messageMonitor(config. messageMonitor(
415+ DisruptorCommandBus . class, " commandBus"
416+ ))
417+ .bufferSize(4096 )
418+ // ...
419+ .build();
420+ commandBus. registerHandlerInterceptor(new CorrelationDataInterceptor<> (config. correlationDataProviders()));
421+ return commandBus;
422+ });
423+ }
424+ }
360425```
361426{% endtab %}
362427
363428{% tab title="Spring Boot AutoConfiguration" %}
364429``` java
365- @Bean
366- public DisruptorCommandBus commandBus(TransactionManager txManager, AxonConfiguration axonConfiguration) {
367- DisruptorCommandBus commandBus =
368- DisruptorCommandBus . builder()
369- .transactionManager(txManager)
370- .messageMonitor(axonConfiguration. messageMonitor(DisruptorCommandBus . class, " commandBus" ))
371- .build();
372- commandBus. registerHandlerInterceptor(new CorrelationDataInterceptor<> (axonConfiguration. correlationDataProviders()));
373- return commandBus;
430+ @Configuration
431+ public class AxonConfig {
432+ // omitting other configuration methods...
433+ @Bean
434+ public CommandBus disruptorCommandBus (TransactionManager transactionManager ,
435+ GlobalMetricRegistry metricRegistry ) {
436+ return DisruptorCommandBus . builder()
437+ .transactionManager(transactionManager)
438+ .messageMonitor(metricRegistry. registerCommandBus(" commandBus" ))
439+ .bufferSize(4096 )
440+ // ...
441+ .build();
442+ }
443+
444+ @Bean
445+ public ConfigurerModule commandBusCorrelationConfigurerModule () {
446+ return configurer - > configurer. onInitialize(
447+ config - > config. commandBus(). registerHandlerInterceptor(
448+ new CorrelationDataInterceptor<> (config. correlationDataProviders())
449+ )
450+ );
451+ }
374452}
375453```
376454{% endtab %}
@@ -466,7 +544,7 @@ When we need to deviate from the default `AnnotationRoutingStrategy`, we should
466544{% tab title="Axon Configuration API" %}
467545``` java
468546public class AxonConfig {
469- // ...
547+ // omitting other configuration methods ...
470548 public void configureRoutingStrategy (Configurer configurer , YourRoutingStrategy yourRoutingStrategy ) {
471549 configurer. registerComponent(RoutingStrategy . class, config - > yourRoutingStrategy);
472550 }
@@ -478,7 +556,7 @@ public class AxonConfig {
478556``` java
479557@Configuration
480558public class AxonConfig {
481- // ...
559+ // omitting other configuration methods ...
482560 @Bean
483561 public RoutingStrategy routingStrategy () {
484562 return /* construct your routing strategy */ ;
0 commit comments