Java Code Examples for org.springframework.jms.config.JmsListenerEndpointRegistry
The following examples show how to use
org.springframework.jms.config.JmsListenerEndpointRegistry. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note Source File: AbstractJmsAnnotationDrivenTests.java License: MIT License | 6 votes |
/** * 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 */ public void testCustomConfiguration(ApplicationContext context) { JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class); JmsListenerContainerTestFactory customFactory = context.getBean("customFactory", JmsListenerContainerTestFactory.class); assertEquals(1, defaultFactory.getListenerContainers().size()); assertEquals(1, customFactory.getListenerContainers().size()); JmsListenerEndpoint endpoint = defaultFactory.getListenerContainers().get(0).getEndpoint(); assertEquals("Wrong endpoint type", SimpleJmsListenerEndpoint.class, endpoint.getClass()); assertEquals("Wrong listener set in custom endpoint", context.getBean("simpleMessageListener"), ((SimpleJmsListenerEndpoint) endpoint).getMessageListener()); JmsListenerEndpointRegistry customRegistry = context.getBean("customRegistry", JmsListenerEndpointRegistry.class); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainerIds().size()); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainers().size()); assertNotNull("Container with custom id on the annotation should be found", customRegistry.getListenerContainer("listenerId")); assertNotNull("Container created with custom id should be found", customRegistry.getListenerContainer("myCustomEndpointId")); }
Example 2
Source Project: java-technology-stack Source File: AbstractJmsAnnotationDrivenTests.java License: MIT License | 6 votes |
/** * 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 */ public void testCustomConfiguration(ApplicationContext context) { JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class); JmsListenerContainerTestFactory customFactory = context.getBean("customFactory", JmsListenerContainerTestFactory.class); assertEquals(1, defaultFactory.getListenerContainers().size()); assertEquals(1, customFactory.getListenerContainers().size()); JmsListenerEndpoint endpoint = defaultFactory.getListenerContainers().get(0).getEndpoint(); assertEquals("Wrong endpoint type", SimpleJmsListenerEndpoint.class, endpoint.getClass()); assertEquals("Wrong listener set in custom endpoint", context.getBean("simpleMessageListener"), ((SimpleJmsListenerEndpoint) endpoint).getMessageListener()); JmsListenerEndpointRegistry customRegistry = context.getBean("customRegistry", JmsListenerEndpointRegistry.class); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainerIds().size()); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainers().size()); assertNotNull("Container with custom id on the annotation should be found", customRegistry.getListenerContainer("listenerId")); assertNotNull("Container created with custom id should be found", customRegistry.getListenerContainer("myCustomEndpointId")); }
Example 3
Source Project: spring4-understanding Source File: AbstractJmsAnnotationDrivenTests.java License: Apache License 2.0 | 6 votes |
/** * 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 */ public void testCustomConfiguration(ApplicationContext context) { JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class); JmsListenerContainerTestFactory customFactory = context.getBean("customFactory", JmsListenerContainerTestFactory.class); assertEquals(1, defaultFactory.getListenerContainers().size()); assertEquals(1, customFactory.getListenerContainers().size()); JmsListenerEndpoint endpoint = defaultFactory.getListenerContainers().get(0).getEndpoint(); assertEquals("Wrong endpoint type", SimpleJmsListenerEndpoint.class, endpoint.getClass()); assertEquals("Wrong listener set in custom endpoint", context.getBean("simpleMessageListener"), ((SimpleJmsListenerEndpoint) endpoint).getMessageListener()); JmsListenerEndpointRegistry customRegistry = context.getBean("customRegistry", JmsListenerEndpointRegistry.class); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainerIds().size()); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainers().size()); assertNotNull("Container with custom id on the annotation should be found", customRegistry.getListenerContainer("listenerId")); assertNotNull("Container created with custom id should be found", customRegistry.getListenerContainer("myCustomEndpointId")); }
Example 4
Source Project: spring-analysis-note Source File: JmsListenerAnnotationBeanPostProcessor.java License: MIT License | 5 votes |
@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(); }
Example 5
Source Project: spring-analysis-note Source File: JmsListenerAnnotationBeanPostProcessor.java License: MIT License | 5 votes |
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof AopInfrastructureBean || bean instanceof JmsListenerContainerFactory || bean instanceof JmsListenerEndpointRegistry) { // Ignore AOP infrastructure such as scoped proxies. return bean; } Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean); if (!this.nonAnnotatedClasses.contains(targetClass) && AnnotationUtils.isCandidateClass(targetClass, JmsListener.class)) { Map<Method, Set<JmsListener>> annotatedMethods = MethodIntrospector.selectMethods(targetClass, (MethodIntrospector.MetadataLookup<Set<JmsListener>>) method -> { Set<JmsListener> listenerMethods = AnnotatedElementUtils.getMergedRepeatableAnnotations( method, JmsListener.class, JmsListeners.class); return (!listenerMethods.isEmpty() ? listenerMethods : null); }); if (annotatedMethods.isEmpty()) { this.nonAnnotatedClasses.add(targetClass); if (logger.isTraceEnabled()) { logger.trace("No @JmsListener annotations found on bean type: " + targetClass); } } else { // Non-empty set of methods annotatedMethods.forEach((method, listeners) -> listeners.forEach(listener -> processJmsListener(listener, method, bean))); if (logger.isDebugEnabled()) { logger.debug(annotatedMethods.size() + " @JmsListener methods processed on bean '" + beanName + "': " + annotatedMethods); } } } return bean; }
Example 6
Source Project: spring-analysis-note Source File: EnableJmsTests.java License: MIT License | 5 votes |
@Test public void containerCanBeStarterViaTheRegistry() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( EnableJmsAutoStartupFalseConfig.class, DefaultBean.class); JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class); MessageListenerTestContainer container = factory.getListenerContainers().get(0); assertFalse(container.isAutoStartup()); assertFalse(container.isStarted()); JmsListenerEndpointRegistry registry = context.getBean(JmsListenerEndpointRegistry.class); registry.start(); assertTrue(container.isStarted()); }
Example 7
Source Project: java-technology-stack Source File: JmsListenerAnnotationBeanPostProcessor.java License: MIT License | 5 votes |
@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(); }
Example 8
Source Project: java-technology-stack Source File: JmsListenerAnnotationBeanPostProcessor.java License: MIT License | 5 votes |
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof AopInfrastructureBean || bean instanceof JmsListenerContainerFactory || bean instanceof JmsListenerEndpointRegistry) { // Ignore AOP infrastructure such as scoped proxies. return bean; } Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean); if (!this.nonAnnotatedClasses.contains(targetClass)) { Map<Method, Set<JmsListener>> annotatedMethods = MethodIntrospector.selectMethods(targetClass, (MethodIntrospector.MetadataLookup<Set<JmsListener>>) method -> { Set<JmsListener> listenerMethods = AnnotatedElementUtils.getMergedRepeatableAnnotations( method, JmsListener.class, JmsListeners.class); return (!listenerMethods.isEmpty() ? listenerMethods : null); }); if (annotatedMethods.isEmpty()) { this.nonAnnotatedClasses.add(targetClass); if (logger.isTraceEnabled()) { logger.trace("No @JmsListener annotations found on bean type: " + targetClass); } } else { // Non-empty set of methods annotatedMethods.forEach((method, listeners) -> listeners.forEach(listener -> processJmsListener(listener, method, bean))); if (logger.isDebugEnabled()) { logger.debug(annotatedMethods.size() + " @JmsListener methods processed on bean '" + beanName + "': " + annotatedMethods); } } } return bean; }
Example 9
Source Project: java-technology-stack Source File: EnableJmsTests.java License: MIT License | 5 votes |
@Test public void containerCanBeStarterViaTheRegistry() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( EnableJmsAutoStartupFalseConfig.class, DefaultBean.class); JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class); MessageListenerTestContainer container = factory.getListenerContainers().get(0); assertFalse(container.isAutoStartup()); assertFalse(container.isStarted()); JmsListenerEndpointRegistry registry = context.getBean(JmsListenerEndpointRegistry.class); registry.start(); assertTrue(container.isStarted()); }
Example 10
Source Project: spring4-understanding Source File: JmsListenerAnnotationBeanPostProcessor.java License: Apache License 2.0 | 5 votes |
@Override public void afterSingletonsInstantiated() { this.registrar.setBeanFactory(this.beanFactory); if (this.beanFactory instanceof ListableBeanFactory) { Map<String, JmsListenerConfigurer> instances = ((ListableBeanFactory) this.beanFactory).getBeansOfType(JmsListenerConfigurer.class); for (JmsListenerConfigurer configurer : instances.values()) { configurer.configureJmsListeners(this.registrar); } } if (this.registrar.getEndpointRegistry() == null) { 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); } if (this.containerFactoryBeanName != null) { this.registrar.setContainerFactoryBeanName(this.containerFactoryBeanName); } // 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(); }
Example 11
Source Project: flowable-engine Source File: EventRegistryJmsConfiguration.java License: Apache License 2.0 | 5 votes |
@Bean public JmsChannelModelProcessor jmsChannelDefinitionProcessor(JmsListenerEndpointRegistry endpointRegistry, JmsOperations jmsOperations) { JmsChannelModelProcessor jmsChannelDeployer = new JmsChannelModelProcessor(); jmsChannelDeployer.setEndpointRegistry(endpointRegistry); jmsChannelDeployer.setJmsOperations(jmsOperations); return jmsChannelDeployer; }
Example 12
Source Project: herd Source File: SearchIndexUpdateJmsMessageListener.java License: Apache License 2.0 | 5 votes |
/** * 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); } }
Example 13
Source Project: herd Source File: HerdJmsMessageListener.java License: Apache License 2.0 | 5 votes |
/** * 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); } }
Example 14
Source Project: herd Source File: SampleDataJmsMessageListenerTest.java License: Apache License 2.0 | 5 votes |
@Bean(name = "org.springframework.jms.config.internalJmsListenerEndpointRegistry") JmsListenerEndpointRegistry registry() { //if Mockito not found return null try { Class.forName("org.mockito.Mockito"); } catch (ClassNotFoundException ignored) { return null; } return Mockito.mock(JmsListenerEndpointRegistry.class); }
Example 15
Source Project: herd Source File: SampleDataJmsMessageListenerTest.java License: Apache License 2.0 | 5 votes |
@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(); }
Example 16
Source Project: herd Source File: SearchIndexUpdateJmsMessageListenerTest.java License: Apache License 2.0 | 5 votes |
@Bean(name = "org.springframework.jms.config.internalJmsListenerEndpointRegistry") JmsListenerEndpointRegistry registry() { //if Mockito not found return null try { Class.forName("org.mockito.Mockito"); } catch (ClassNotFoundException ignored) { return null; } return Mockito.mock(JmsListenerEndpointRegistry.class); }
Example 17
Source Project: herd Source File: SearchIndexUpdateJmsMessageListenerTest.java License: Apache License 2.0 | 5 votes |
@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(); }
Example 18
Source Project: herd Source File: HerdJmsMessageListenerTest.java License: Apache License 2.0 | 5 votes |
@Bean(name = "org.springframework.jms.config.internalJmsListenerEndpointRegistry") JmsListenerEndpointRegistry registry() { //if Mockito not found return null try { Class.forName("org.mockito.Mockito"); } catch (ClassNotFoundException ignored) { return null; } return Mockito.mock(JmsListenerEndpointRegistry.class); }
Example 19
Source Project: herd Source File: HerdJmsMessageListenerTest.java License: Apache License 2.0 | 5 votes |
@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(); }
Example 20
Source Project: herd Source File: StoragePolicyProcessorJmsMessageListenerTest.java License: Apache License 2.0 | 5 votes |
@Bean(name = "org.springframework.jms.config.internalJmsListenerEndpointRegistry") JmsListenerEndpointRegistry registry() { //if Mockito not found return null try { Class.forName("org.mockito.Mockito"); } catch (ClassNotFoundException ignored) { return null; } return Mockito.mock(JmsListenerEndpointRegistry.class); }
Example 21
Source Project: herd Source File: StoragePolicyProcessorJmsMessageListenerTest.java License: Apache License 2.0 | 5 votes |
@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(); }
Example 22
Source Project: spring-cloud-sleuth Source File: TraceMessagingAutoConfiguration.java License: Apache License 2.0 | 5 votes |
@Bean JmsListenerConfigurer configureTracing(BeanFactory beanFactory, JmsListenerEndpointRegistry defaultRegistry) { return registrar -> { TracingJmsBeanPostProcessor processor = beanFactory .getBean(TracingJmsBeanPostProcessor.class); JmsListenerEndpointRegistry registry = registrar.getEndpointRegistry(); registrar.setEndpointRegistry((JmsListenerEndpointRegistry) processor .wrap(registry == null ? defaultRegistry : registry)); }; }
Example 23
Source Project: spring-cloud-sleuth Source File: TraceMessagingAutoConfiguration.java License: Apache License 2.0 | 5 votes |
Object wrap(Object bean) { if (typeMatches(bean)) { return new TracingJmsListenerEndpointRegistry( (JmsListenerEndpointRegistry) bean, this.beanFactory); } return bean; }
Example 24
Source Project: spring-analysis-note Source File: JmsBootstrapConfiguration.java License: MIT License | 4 votes |
@Bean(name = JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME) public JmsListenerEndpointRegistry defaultJmsListenerEndpointRegistry() { return new JmsListenerEndpointRegistry(); }
Example 25
Source Project: spring-analysis-note Source File: JmsListenerAnnotationBeanPostProcessorTests.java License: MIT License | 4 votes |
@Bean public JmsListenerEndpointRegistry jmsListenerEndpointRegistry() { return new JmsListenerEndpointRegistry(); }
Example 26
Source Project: spring-analysis-note Source File: EnableJmsTests.java License: MIT License | 4 votes |
@Bean public JmsListenerEndpointRegistry customRegistry() { return new JmsListenerEndpointRegistry(); }
Example 27
Source Project: java-technology-stack Source File: JmsBootstrapConfiguration.java License: MIT License | 4 votes |
@Bean(name = JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME) public JmsListenerEndpointRegistry defaultJmsListenerEndpointRegistry() { return new JmsListenerEndpointRegistry(); }
Example 28
Source Project: java-technology-stack Source File: JmsListenerAnnotationBeanPostProcessorTests.java License: MIT License | 4 votes |
@Bean public JmsListenerEndpointRegistry jmsListenerEndpointRegistry() { return new JmsListenerEndpointRegistry(); }
Example 29
Source Project: java-technology-stack Source File: EnableJmsTests.java License: MIT License | 4 votes |
@Bean public JmsListenerEndpointRegistry customRegistry() { return new JmsListenerEndpointRegistry(); }
Example 30
Source Project: spring4-understanding Source File: JmsBootstrapConfiguration.java License: Apache License 2.0 | 4 votes |
@Bean(name = JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME) public JmsListenerEndpointRegistry defaultJmsListenerEndpointRegistry() { return new JmsListenerEndpointRegistry(); }