@Scheduled(fixedDelay = 60000) fun controlHerdJmsMessageListener() { try { val jmsMessageListenerEnabled: Boolean = java.lang.Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.JMS_LISTENER_ENABLED)) val registry: JmsListenerEndpointRegistry = ApplicationContextHolder.getApplicationContext().getBean( "org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry::class.java ) val jmsMessageListenerContainer: MessageListenerContainer = registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING) LOGGER.debug( "controlHerdJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}", ConfigurationValue.JMS_LISTENER_ENABLED.getKey(), jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning() ) if (!jmsMessageListenerEnabled && jmsMessageListenerContainer.isRunning()) { LOGGER.info("controlHerdJmsMessageListener(): Stopping the herd JMS message listener ...") jmsMessageListenerContainer.stop() LOGGER.info("controlHerdJmsMessageListener(): Done") } else if (jmsMessageListenerEnabled && !jmsMessageListenerContainer.isRunning()) { LOGGER.info("controlHerdJmsMessageListener(): Starting the herd JMS message listener ...") jmsMessageListenerContainer.start() LOGGER.info("controlHerdJmsMessageListener(): Done") } } catch (e: Exception) { LOGGER.error( "controlHerdJmsMessageListener(): Failed to control the herd Jms message listener service.", e ) } }
Periodically check the configuration and apply the action to the herd JMS message listener service , if needed .