AxonFramework icon indicating copy to clipboard operation
AxonFramework copied to clipboard

Add ConditionalOnBean to InfraConfiguration Beans

Open nils-christian opened this issue 3 years ago • 3 comments

Feature Description

Currently it is possible to customize almost everything in Axon's Spring Boot configuration (which we rely heavily on) simply by providing the necessary beans, as most configuration use Spring's ConditionalOnBean annotation to skip the beans configured by the application. However, this is not the case for certain beans in InfraConfiguration.

Our specific target for this is the SpringAxonConfiguration. We want to control the starting (and stopping) of the Axon framework ourselves based on some custom application events (we are aware of the delayed event processing start feature, but we want to control some more aspects and especially the stopping as well). Normally we would simply provide a custom bean for this, but due to the missing annotation this is not possible.

@Bean
SpringAxonConfiguration springAxonConfiguration( final Configurer configurer ) {
	return new MySpringAxonConfiguration( configurer );
}

final class MySpringAxonConfiguration extends SpringAxonConfiguration {

	public MySpringAxonConfiguration( final Configurer configurer ) {
		super( configurer );
	}

	@Override
	public void start( ) {
		// Disable default behaviour
	}

	@Override
	public void stop( ) {
		// Disable default behaviour
	}
	
	// Start/Stop Axon based on some custom application events

}

Current Behaviour

The beans in InfraConfiguration cannot be overriden without "spring.main.allow-bean-definition-overriding=true".

Wanted Behaviour

The beans in InfraConfiguration are only created if the application does not provide them already.

Possible Workarounds

Use "spring.main.allow-bean-definition-overriding=true".

nils-christian avatar Sep 20 '22 15:09 nils-christian

Fair addition, @nils-christian. Shouldn't be to tough to introduce, either.

As you've put it right, this is a feature. So I won't expect this to be included in 4.6.x, but rather 4.7.0. Although that may sound scary, given that the release of 4.6.0 took quite long (understatement to be honest), I can assure you we are not planning to withhold a 4.7.0 release for this long.

Now, aside from that, I want to notify you of an addition we did in 4.6.0, which is the AxonStartedEvent. This Spring Event is published by the framework to signal that all your message handlers have been registered and ready for progress. Noted, that doesn't do anything for the stop, yet.

So, out of curiosity, would you think using the AxonStartedEvent solves your "I need to do xyz at start" predicament? If so, can you imagine an AxonStoppedEvent would solve the other part too?

smcvb avatar Sep 20 '22 15:09 smcvb

Hi @smcvb,

To be honest - no, it wouldn't solve our issue. We are running through multiple phases during the startup (and shutdown) of our application and Axon is one of them. So it is not about being informed when Axon is ready but rather making sure that Axon starts/stops when our application says so ;)

nils-christian avatar Sep 20 '22 16:09 nils-christian

Alright, thanks for the feedback, @nils-christian :+1:

smcvb avatar Sep 21 '22 08:09 smcvb

Hi @nils-christian, if you have the time, let me know whether the provided PR is sufficient for the level of customization you're looking for.

smcvb avatar Dec 20 '22 15:12 smcvb