use of org.springframework.jms.config.JmsListenerEndpointRegistry in project herd by FINRAOS.
the class HerdJmsMessageListener method controlHerdJmsMessageListener.
/**
* Periodically check the configuration and apply the action to the herd JMS message listener service, if needed.
*/
@Scheduled(fixedDelay = 60000)
public void controlHerdJmsMessageListener() {
try {
// Get the configuration setting.
Boolean jmsMessageListenerEnabled = Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.JMS_LISTENER_ENABLED));
// Get the registry bean.
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
// Get the herd JMS message listener container.
MessageListenerContainer jmsMessageListenerContainer = registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING);
// Get the current JMS message listener status and the configuration value.
LOGGER.debug("controlHerdJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}", ConfigurationValue.JMS_LISTENER_ENABLED.getKey(), jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning());
// Apply the relative action if needed.
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 (Exception e) {
LOGGER.error("controlHerdJmsMessageListener(): Failed to control the herd Jms message listener service.", e);
}
}
use of org.springframework.jms.config.JmsListenerEndpointRegistry in project herd by FINRAOS.
the class StoragePolicyProcessorJmsMessageListener method controlStoragePolicyProcessorJmsMessageListener.
/**
* Periodically check the configuration and apply the action to the storage policy processor JMS message listener service, if needed.
*/
@Scheduled(fixedDelay = 60000)
public void controlStoragePolicyProcessorJmsMessageListener() {
try {
// Get the configuration setting.
Boolean jmsMessageListenerEnabled = Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.STORAGE_POLICY_PROCESSOR_JMS_LISTENER_ENABLED));
// Get the registry bean.
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
// Get the storage policy processor JMS message listener container.
MessageListenerContainer jmsMessageListenerContainer = registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE);
// Get the current JMS message listener status and the configuration value.
LOGGER.debug("controlStoragePolicyProcessorJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}", ConfigurationValue.STORAGE_POLICY_PROCESSOR_JMS_LISTENER_ENABLED.getKey(), jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning());
// Apply the relative action if needed.
if (!jmsMessageListenerEnabled && jmsMessageListenerContainer.isRunning()) {
LOGGER.info("controlStoragePolicyProcessorJmsMessageListener(): Stopping the storage policy processor JMS message listener ...");
jmsMessageListenerContainer.stop();
LOGGER.info("controlStoragePolicyProcessorJmsMessageListener(): Done");
} else if (jmsMessageListenerEnabled && !jmsMessageListenerContainer.isRunning()) {
LOGGER.info("controlStoragePolicyProcessorJmsMessageListener(): Starting the storage policy processor JMS message listener ...");
jmsMessageListenerContainer.start();
LOGGER.info("controlStoragePolicyProcessorJmsMessageListener(): Done");
}
} catch (Exception e) {
LOGGER.error("controlStoragePolicyProcessorJmsMessageListener(): Failed to control the storage policy processor Jms message listener service.", e);
}
}
use of org.springframework.jms.config.JmsListenerEndpointRegistry in project herd by FINRAOS.
the class SampleDataJmsMessageListener method controlSampleDataJmsMessageListener.
/**
* Periodically check the configuration and apply the action to the storage policy processor JMS message listener service, if needed.
*/
@Scheduled(fixedDelay = 60000)
public void controlSampleDataJmsMessageListener() {
try {
// Get the configuration setting.
Boolean jmsMessageListenerEnabled = Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.SAMPLE_DATA_JMS_LISTENER_ENABLED));
// Get the registry bean.
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
// Get the sample data JMS message listener container.
MessageListenerContainer jmsMessageListenerContainer = registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE);
// Get the current JMS message listener status and the configuration value.
LOGGER.debug("controlStoragePolicyProcessorJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}", ConfigurationValue.SAMPLE_DATA_JMS_LISTENER_ENABLED.getKey(), jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning());
// Apply the relative action if needed.
if (!jmsMessageListenerEnabled && jmsMessageListenerContainer.isRunning()) {
LOGGER.info("controlSampleDataJmsMessageListener(): Stopping the sample data JMS message listener ...");
jmsMessageListenerContainer.stop();
LOGGER.info("controlSampleDataJmsMessageListener(): Done");
} else if (jmsMessageListenerEnabled && !jmsMessageListenerContainer.isRunning()) {
LOGGER.info("controlSampleDataJmsMessageListener(): Starting the sample data JMS message listener ...");
jmsMessageListenerContainer.start();
LOGGER.info("controlSampleDataJmsMessageListener(): Done");
}
} catch (Exception e) {
LOGGER.error("controlSampleDataJmsMessageListener(): Failed to control the sample data Jms message listener service.", e);
}
}
use of org.springframework.jms.config.JmsListenerEndpointRegistry in project herd by FINRAOS.
the class SampleDataJmsMessageListenerTest method testControlListener.
@Test
public void testControlListener() {
configurationHelper = Mockito.mock(ConfigurationHelper.class);
ReflectionTestUtils.setField(sampleDataJmsMessageListener, "configurationHelper", configurationHelper);
MessageListenerContainer mockMessageListenerContainer = Mockito.mock(MessageListenerContainer.class);
// The listener is not enabled
when(configurationHelper.getProperty(ConfigurationValue.SAMPLE_DATA_JMS_LISTENER_ENABLED)).thenReturn("false");
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
when(registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE)).thenReturn(mockMessageListenerContainer);
// the listener is not running, nothing happened
when(mockMessageListenerContainer.isRunning()).thenReturn(false);
sampleDataJmsMessageListener.controlSampleDataJmsMessageListener();
verify(mockMessageListenerContainer, Mockito.times(0)).stop();
verify(mockMessageListenerContainer, Mockito.times(0)).start();
// the listener is running, but it is not enable, should stop
when(mockMessageListenerContainer.isRunning()).thenReturn(true);
sampleDataJmsMessageListener.controlSampleDataJmsMessageListener();
verify(mockMessageListenerContainer).stop();
// The listener is enabled
when(configurationHelper.getProperty(ConfigurationValue.SAMPLE_DATA_JMS_LISTENER_ENABLED)).thenReturn("true");
// the listener is running, should not call the start method
when(mockMessageListenerContainer.isRunning()).thenReturn(true);
sampleDataJmsMessageListener.controlSampleDataJmsMessageListener();
verify(mockMessageListenerContainer, Mockito.times(0)).start();
// the listener is not running, but it is enabled, should start
when(mockMessageListenerContainer.isRunning()).thenReturn(false);
sampleDataJmsMessageListener.controlSampleDataJmsMessageListener();
verify(mockMessageListenerContainer).start();
}
use of org.springframework.jms.config.JmsListenerEndpointRegistry in project spring-framework by spring-projects.
the class JmsListenerAnnotationBeanPostProcessor method afterSingletonsInstantiated.
@Override
public void afterSingletonsInstantiated() {
// Remove resolved singleton classes from cache
this.nonAnnotatedClasses.clear();
if (this.beanFactory instanceof ListableBeanFactory) {
// Apply JmsListenerConfigurer beans from the BeanFactory, if any
Map<String, JmsListenerConfigurer> beans = ((ListableBeanFactory) this.beanFactory).getBeansOfType(JmsListenerConfigurer.class);
List<JmsListenerConfigurer> configurers = new ArrayList<>(beans.values());
AnnotationAwareOrderComparator.sort(configurers);
for (JmsListenerConfigurer configurer : configurers) {
configurer.configureJmsListeners(this.registrar);
}
}
if (this.containerFactoryBeanName != null) {
this.registrar.setContainerFactoryBeanName(this.containerFactoryBeanName);
}
if (this.registrar.getEndpointRegistry() == null) {
// Determine JmsListenerEndpointRegistry bean from the BeanFactory
if (this.endpointRegistry == null) {
Assert.state(this.beanFactory != null, "BeanFactory must be set to find endpoint registry by bean name");
this.endpointRegistry = this.beanFactory.getBean(JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME, JmsListenerEndpointRegistry.class);
}
this.registrar.setEndpointRegistry(this.endpointRegistry);
}
// Set the custom handler method factory once resolved by the configurer
MessageHandlerMethodFactory handlerMethodFactory = this.registrar.getMessageHandlerMethodFactory();
if (handlerMethodFactory != null) {
this.messageHandlerMethodFactory.setMessageHandlerMethodFactory(handlerMethodFactory);
}
// Actually register all listeners
this.registrar.afterPropertiesSet();
}
Aggregations