Description
Expected Behavior
It should be possible to configure the default behavior and disable utilization of micrometer in context of the AMQP integration, particularly the AbstractMessageListenerContainer
, before it even attempts to establish the micrometer support via creating a MicrometerHolder
. A convenient way would be the possibility to configure the attribute AbstractMessageListenerContainer.micrometerEnabled
and set it to false during the initialization, if needed.
If the case, that multiple instances of MeterRegistry
s are available in the application context, is actually relevant and not just a theoretical case, it should be possible to specify the particular MeterRegistry
(instantiable) subclass via configuration.
Current Behavior
Currently, the utilization of micrometer by the AbstractMessageListenerContainer
is enabled by default when micrometer (or rather io.micrometer.core.instrument.MeterRegistry
) is found on the classpath. So, when micrometer is used by any part of the application, it is also enabled by default for the *MessageListenerContainers, even if not wanted or not needed.
Additionally, during instantiation of the MicrometerHolder
there is an assumption that only a single instance of MeterRegistry
can be present in the application context. Technically, it might be possible to have more than one MeterRegistry
and in that case it is not possible to specify, which particular MeterRegistry
should be used and the message "No micrometer registry present" would also be misleading in that case.
Context
In our application, we're collecting some business related metrics using an InfluxMeterRegistry
which should not automatically be used in context of our RabbitMQ integration via spring-amqp. The most convenient way, at least for us, to avoid this utilization would be to make AbstractMessageListenerContainer.micrometerEnabled
configurable, so we could just configure it to be false.
Setting the AbstractMessageListenerContainer.micrometerEnabled
attribute to false at the right moment during bean initialization via customized post-processing seems not to be possible, at least in our case, where the SimpleMessageListenerContainer
is created and also initialized (including afterPropertiesSet()) as part of the call invokeInitMethods(beanName, wrappedBean, mbd);
inside AbstractAutowireCapableBeanFactory.initializeBean(...)
while the post-processings are applied right before and right after this whole step. Actually, a post-processing between creation and initialization, probably as a part of the ListenerContainerFactoryBean
would be needed to programmatically set the micrometerEnabled
flag which seems to be currently not in place for the instantiation of SimpleMessageListenerContainer
s.