How do i disable jms listener in my local environment? Since i am not connecting to MQ from the local enviroment, i donot want my console logs to get flooded with trying to connect MQ message. So i want to disable it locally.
I am using Spring boot and annotation based programming.I saw posts here suggesting to put autoStartup to false in properties but i cannot do that because i use spring boot. I have commented all the code related to jms right now but how do we make jms listener run only in UAT or Prod server not on local server?
My code:
// @JmsListener(destination = "TOBUS", containerFactory = "defaultJmsListenerContainerFactory")
public void onMessage(final TextMessage message) throws JMSException {//some code here}
Thanks
spring.jms.listener.auto-startup=false
This worked for me
The question is old but maybe can still interests someone.
There is at least two options to achieve this :
Is is not tell if this is already the case but first I would set the listening method in a separate bean. Appart from the fact that the proposed solutions work only with this kind of code organisation, it is better in term of Separation of Concerns/Responsability and then easier for implementing unit tests, the former implies the latter.
@Profile("!local")
@Component
public class MyBeanListener {
@JmsListener(destination = "TOBUS", containerFactory = "defaultJmsListenerContainerFactory")
public void onMessage(final TextMessage message) throws JMSException {//some code here}
}
Then start your application with the profile 'local' defines.
@ConditionalOnProperty(name = "jms.listener.enable", havingValue = "true", matchIfMissing = true)
@Component
public class MyBeanListener {
@JmsListener(destination = "TOBUS", containerFactory = "defaultJmsListenerContainerFactory")
public void onMessage(final TextMessage message) throws JMSException {//some code here}
}
Then define a property "jms.listener.enable=false" only for your local environment (https://docs.spring.io/spring-boot/docs/3.0.x/reference/html/features.html#features.external-config)
NB : These annotations work at beans definition level (on @Configuration classes or on @Bean method factory), then setting them on the @JmsListener annotated method will have not effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With