use of org.springframework.jms.config.JmsListenerEndpointRegistry in project spring-framework by spring-projects.
the class AbstractJmsAnnotationDrivenTests method testCustomConfiguration.
/**
* Test for {@link CustomBean} and an manually endpoint registered
* with "myCustomEndpointId". The custom endpoint does not provide
* any factory so it's registered with the default one
*/
protected void testCustomConfiguration(ApplicationContext context) {
JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
JmsListenerContainerTestFactory customFactory = context.getBean("customFactory", JmsListenerContainerTestFactory.class);
assertThat(defaultFactory.getListenerContainers().size()).isEqualTo(1);
assertThat(customFactory.getListenerContainers().size()).isEqualTo(1);
JmsListenerEndpoint endpoint = defaultFactory.getListenerContainers().get(0).getEndpoint();
assertThat(endpoint.getClass()).as("Wrong endpoint type").isEqualTo(SimpleJmsListenerEndpoint.class);
assertThat(((SimpleJmsListenerEndpoint) endpoint).getMessageListener()).as("Wrong listener set in custom endpoint").isEqualTo(context.getBean("simpleMessageListener"));
JmsListenerEndpointRegistry customRegistry = context.getBean("customRegistry", JmsListenerEndpointRegistry.class);
assertThat(customRegistry.getListenerContainerIds().size()).as("Wrong number of containers in the registry").isEqualTo(2);
assertThat(customRegistry.getListenerContainers().size()).as("Wrong number of containers in the registry").isEqualTo(2);
assertThat(customRegistry.getListenerContainer("listenerId")).as("Container with custom id on the annotation should be found").isNotNull();
assertThat(customRegistry.getListenerContainer("myCustomEndpointId")).as("Container created with custom id should be found").isNotNull();
}
use of org.springframework.jms.config.JmsListenerEndpointRegistry in project herd by FINRAOS.
the class SearchIndexUpdateJmsMessageListener method controlSearchIndexUpdateJmsMessageListener.
/**
* Periodically check the configuration and apply the action to the storage policy processor JMS message listener service, if needed.
*/
@Scheduled(fixedDelay = 60000)
public void controlSearchIndexUpdateJmsMessageListener() {
try {
// Get the configuration setting.
Boolean jmsMessageListenerEnabled = Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.SEARCH_INDEX_UPDATE_JMS_LISTENER_ENABLED));
// Get the registry bean.
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
// Get the search index update JMS message listener container.
MessageListenerContainer jmsMessageListenerContainer = registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_SEARCH_INDEX_UPDATE_QUEUE);
// Get the current JMS message listener status and the configuration value.
LOGGER.debug("controlSearchIndexUpdateJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}", ConfigurationValue.SEARCH_INDEX_UPDATE_JMS_LISTENER_ENABLED.getKey(), jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning());
// Apply the relative action if needed.
if (!jmsMessageListenerEnabled && jmsMessageListenerContainer.isRunning()) {
LOGGER.info("controlSearchIndexUpdateJmsMessageListener(): Stopping the search index update JMS message listener ...");
jmsMessageListenerContainer.stop();
LOGGER.info("controlSearchIndexUpdateJmsMessageListener(): Done");
} else if (jmsMessageListenerEnabled && !jmsMessageListenerContainer.isRunning()) {
LOGGER.info("controlSearchIndexUpdateJmsMessageListener(): Starting the search index update JMS message listener ...");
jmsMessageListenerContainer.start();
LOGGER.info("controlSearchIndexUpdateJmsMessageListener(): Done");
}
} catch (Exception e) {
LOGGER.error("controlSearchIndexUpdateJmsMessageListener(): Failed to control the search index update Jms message listener service.", e);
}
}
use of org.springframework.jms.config.JmsListenerEndpointRegistry in project herd by FINRAOS.
the class HerdJmsMessageListenerTest method testControlListener.
@Test
public void testControlListener() {
configurationHelper = Mockito.mock(ConfigurationHelper.class);
ReflectionTestUtils.setField(herdJmsMessageListener, "configurationHelper", configurationHelper);
MessageListenerContainer mockMessageListenerContainer = Mockito.mock(MessageListenerContainer.class);
// The listener is not enabled
when(configurationHelper.getProperty(ConfigurationValue.JMS_LISTENER_ENABLED)).thenReturn("false");
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
when(registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING)).thenReturn(mockMessageListenerContainer);
// the listener is not running, nothing happened
when(mockMessageListenerContainer.isRunning()).thenReturn(false);
herdJmsMessageListener.controlHerdJmsMessageListener();
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);
herdJmsMessageListener.controlHerdJmsMessageListener();
verify(mockMessageListenerContainer).stop();
// The listener is enabled
when(configurationHelper.getProperty(ConfigurationValue.JMS_LISTENER_ENABLED)).thenReturn("true");
// the listener is running, should not call the start method
when(mockMessageListenerContainer.isRunning()).thenReturn(true);
herdJmsMessageListener.controlHerdJmsMessageListener();
verify(mockMessageListenerContainer, Mockito.times(0)).start();
// the listener is not running, but it is enabled, should start
when(mockMessageListenerContainer.isRunning()).thenReturn(false);
herdJmsMessageListener.controlHerdJmsMessageListener();
verify(mockMessageListenerContainer).start();
}
use of org.springframework.jms.config.JmsListenerEndpointRegistry in project herd by FINRAOS.
the class StoragePolicyProcessorJmsMessageListenerTest method testControlListener.
@Test
public void testControlListener() {
configurationHelper = Mockito.mock(ConfigurationHelper.class);
ReflectionTestUtils.setField(storagePolicyProcessorJmsMessageListener, "configurationHelper", configurationHelper);
MessageListenerContainer mockMessageListenerContainer = Mockito.mock(MessageListenerContainer.class);
// The listener is not enabled
when(configurationHelper.getProperty(ConfigurationValue.STORAGE_POLICY_PROCESSOR_JMS_LISTENER_ENABLED)).thenReturn("false");
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
when(registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE)).thenReturn(mockMessageListenerContainer);
// the listener is not running, nothing happened
when(mockMessageListenerContainer.isRunning()).thenReturn(false);
storagePolicyProcessorJmsMessageListener.controlStoragePolicyProcessorJmsMessageListener();
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);
storagePolicyProcessorJmsMessageListener.controlStoragePolicyProcessorJmsMessageListener();
verify(mockMessageListenerContainer).stop();
// The listener is enabled
when(configurationHelper.getProperty(ConfigurationValue.STORAGE_POLICY_PROCESSOR_JMS_LISTENER_ENABLED)).thenReturn("true");
// the listener is running, should not call the start method
when(mockMessageListenerContainer.isRunning()).thenReturn(true);
storagePolicyProcessorJmsMessageListener.controlStoragePolicyProcessorJmsMessageListener();
verify(mockMessageListenerContainer, Mockito.times(0)).start();
// the listener is not running, but it is enabled, should start
when(mockMessageListenerContainer.isRunning()).thenReturn(false);
storagePolicyProcessorJmsMessageListener.controlStoragePolicyProcessorJmsMessageListener();
verify(mockMessageListenerContainer).start();
}
use of org.springframework.jms.config.JmsListenerEndpointRegistry in project herd by FINRAOS.
the class SearchIndexUpdateJmsMessageListenerTest method testControlListener.
@Test
public void testControlListener() {
ReflectionTestUtils.setField(searchIndexUpdateJmsMessageListener, "configurationHelper", configurationHelper);
MessageListenerContainer mockMessageListenerContainer = Mockito.mock(MessageListenerContainer.class);
// The listener is not enabled
when(configurationHelper.getProperty(ConfigurationValue.SEARCH_INDEX_UPDATE_JMS_LISTENER_ENABLED)).thenReturn("false");
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
when(registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_SEARCH_INDEX_UPDATE_QUEUE)).thenReturn(mockMessageListenerContainer);
// The listener is not running, nothing happened
when(mockMessageListenerContainer.isRunning()).thenReturn(false);
searchIndexUpdateJmsMessageListener.controlSearchIndexUpdateJmsMessageListener();
verify(mockMessageListenerContainer, times(0)).stop();
verify(mockMessageListenerContainer, times(0)).start();
// The listener is running, but it is not enable, should stop
when(mockMessageListenerContainer.isRunning()).thenReturn(true);
searchIndexUpdateJmsMessageListener.controlSearchIndexUpdateJmsMessageListener();
verify(mockMessageListenerContainer, times(1)).stop();
// The listener is enabled
when(configurationHelper.getProperty(ConfigurationValue.SEARCH_INDEX_UPDATE_JMS_LISTENER_ENABLED)).thenReturn("true");
// The listener is running, should not call the start method
when(mockMessageListenerContainer.isRunning()).thenReturn(true);
searchIndexUpdateJmsMessageListener.controlSearchIndexUpdateJmsMessageListener();
verify(mockMessageListenerContainer, times(0)).start();
// The listener is not running, but it is enabled, should start
when(mockMessageListenerContainer.isRunning()).thenReturn(false);
searchIndexUpdateJmsMessageListener.controlSearchIndexUpdateJmsMessageListener();
verify(mockMessageListenerContainer, times(1)).start();
}
Aggregations