Java Code Examples for org.springframework.jms.listener.MessageListenerContainer
The following examples show how to use
org.springframework.jms.listener.MessageListenerContainer. 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: JmsListenerEndpointRegistry.java License: MIT License | 6 votes |
/** * Create a message listener container for the given {@link JmsListenerEndpoint}. * <p>This create the necessary infrastructure to honor that endpoint * with regards to its configuration. * <p>The {@code startImmediately} flag determines if the container should be * started immediately. * @param endpoint the endpoint to add * @param factory the listener factory to use * @param startImmediately start the container immediately if necessary * @see #getListenerContainers() * @see #getListenerContainer(String) */ public void registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory, boolean startImmediately) { Assert.notNull(endpoint, "Endpoint must not be null"); Assert.notNull(factory, "Factory must not be null"); String id = endpoint.getId(); Assert.hasText(id, "Endpoint id must be set"); synchronized (this.listenerContainers) { if (this.listenerContainers.containsKey(id)) { throw new IllegalStateException("Another endpoint is already registered with id '" + id + "'"); } MessageListenerContainer container = createListenerContainer(endpoint, factory); this.listenerContainers.put(id, container); if (startImmediately) { startIfNecessary(container); } } }
Example 2
Source Project: spring-analysis-note Source File: JmsListenerEndpointRegistry.java License: MIT License | 6 votes |
/** * Create and start a new container using the specified factory. */ protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) { MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint); if (listenerContainer instanceof InitializingBean) { try { ((InitializingBean) listenerContainer).afterPropertiesSet(); } catch (Exception ex) { throw new BeanInitializationException("Failed to initialize message listener container", ex); } } int containerPhase = listenerContainer.getPhase(); if (containerPhase < Integer.MAX_VALUE) { // a custom phase value if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) { throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " + this.phase + " vs " + containerPhase); } this.phase = listenerContainer.getPhase(); } return listenerContainer; }
Example 3
Source Project: java-technology-stack Source File: JmsListenerEndpointRegistry.java License: MIT License | 6 votes |
/** * Create a message listener container for the given {@link JmsListenerEndpoint}. * <p>This create the necessary infrastructure to honor that endpoint * with regards to its configuration. * <p>The {@code startImmediately} flag determines if the container should be * started immediately. * @param endpoint the endpoint to add * @param factory the listener factory to use * @param startImmediately start the container immediately if necessary * @see #getListenerContainers() * @see #getListenerContainer(String) */ public void registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory, boolean startImmediately) { Assert.notNull(endpoint, "Endpoint must not be null"); Assert.notNull(factory, "Factory must not be null"); String id = endpoint.getId(); Assert.hasText(id, "Endpoint id must be set"); synchronized (this.listenerContainers) { if (this.listenerContainers.containsKey(id)) { throw new IllegalStateException("Another endpoint is already registered with id '" + id + "'"); } MessageListenerContainer container = createListenerContainer(endpoint, factory); this.listenerContainers.put(id, container); if (startImmediately) { startIfNecessary(container); } } }
Example 4
Source Project: java-technology-stack Source File: JmsListenerEndpointRegistry.java License: MIT License | 6 votes |
/** * Create and start a new container using the specified factory. */ protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) { MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint); if (listenerContainer instanceof InitializingBean) { try { ((InitializingBean) listenerContainer).afterPropertiesSet(); } catch (Exception ex) { throw new BeanInitializationException("Failed to initialize message listener container", ex); } } int containerPhase = listenerContainer.getPhase(); if (containerPhase < Integer.MAX_VALUE) { // a custom phase value if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) { throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " + this.phase + " vs " + containerPhase); } this.phase = listenerContainer.getPhase(); } return listenerContainer; }
Example 5
Source Project: spring4-understanding Source File: JmsListenerEndpointRegistry.java License: Apache License 2.0 | 6 votes |
/** * Create a message listener container for the given {@link JmsListenerEndpoint}. * <p>This create the necessary infrastructure to honor that endpoint * with regards to its configuration. * <p>The {@code startImmediately} flag determines if the container should be * started immediately. * @param endpoint the endpoint to add * @param factory the listener factory to use * @param startImmediately start the container immediately if necessary * @see #getListenerContainers() * @see #getListenerContainer(String) */ public void registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory, boolean startImmediately) { Assert.notNull(endpoint, "Endpoint must not be null"); Assert.notNull(factory, "Factory must not be null"); String id = endpoint.getId(); Assert.notNull(id, "Endpoint id must not be null"); synchronized (this.listenerContainers) { Assert.state(!this.listenerContainers.containsKey(id), "Another endpoint is already registered with id '" + id + "'"); MessageListenerContainer container = createListenerContainer(endpoint, factory); this.listenerContainers.put(id, container); if (startImmediately) { startIfNecessary(container); } } }
Example 6
Source Project: spring4-understanding Source File: JmsListenerEndpointRegistry.java License: Apache License 2.0 | 6 votes |
/** * Create and start a new container using the specified factory. */ protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) { MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint); if (listenerContainer instanceof InitializingBean) { try { ((InitializingBean) listenerContainer).afterPropertiesSet(); } catch (Exception ex) { throw new BeanInitializationException("Failed to initialize message listener container", ex); } } int containerPhase = listenerContainer.getPhase(); if (containerPhase < Integer.MAX_VALUE) { // a custom phase value if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) { throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " + this.phase + " vs " + containerPhase); } this.phase = listenerContainer.getPhase(); } return listenerContainer; }
Example 7
Source Project: spring-cloud-contract Source File: StubRunnerJmsConfiguration.java License: Apache License 2.0 | 6 votes |
private void registerContainers(ConfigurableListableBeanFactory beanFactory, List<Contract> matchingContracts, String flowName, StubRunnerJmsRouter listener) { // listener's container ConnectionFactory connectionFactory = beanFactory .getBean(ConnectionFactory.class); for (Contract matchingContract : matchingContracts) { if (matchingContract.getInput() == null) { continue; } String destination = MapConverter.getStubSideValuesForNonBody( matchingContract.getInput().getMessageFrom()).toString(); MessageListenerContainer container = listenerContainer(destination, connectionFactory, listener); String containerName = flowName + ".container"; Object initializedContainer = beanFactory.initializeBean(container, containerName); beanFactory.registerSingleton(containerName, initializedContainer); } }
Example 8
Source Project: spring-analysis-note Source File: AbstractJmsListenerEndpoint.java License: MIT License | 5 votes |
@Override public void setupListenerContainer(MessageListenerContainer listenerContainer) { if (listenerContainer instanceof AbstractMessageListenerContainer) { setupJmsListenerContainer((AbstractMessageListenerContainer) listenerContainer); } else { new JcaEndpointConfigurer().configureEndpoint(listenerContainer); } }
Example 9
Source Project: spring-analysis-note Source File: JmsListenerEndpointRegistry.java License: MIT License | 5 votes |
@Override public void stop(Runnable callback) { Collection<MessageListenerContainer> listenerContainers = getListenerContainers(); AggregatingCallback aggregatingCallback = new AggregatingCallback(listenerContainers.size(), callback); for (MessageListenerContainer listenerContainer : listenerContainers) { listenerContainer.stop(aggregatingCallback); } }
Example 10
Source Project: spring-analysis-note Source File: JmsListenerEndpointRegistry.java License: MIT License | 5 votes |
@Override public boolean isRunning() { for (MessageListenerContainer listenerContainer : getListenerContainers()) { if (listenerContainer.isRunning()) { return true; } } return false; }
Example 11
Source Project: spring-analysis-note Source File: JmsListenerEndpointRegistry.java License: MIT License | 5 votes |
@Override public void destroy() { for (MessageListenerContainer listenerContainer : getListenerContainers()) { if (listenerContainer instanceof DisposableBean) { try { ((DisposableBean) listenerContainer).destroy(); } catch (Throwable ex) { logger.warn("Failed to destroy message listener container", ex); } } } }
Example 12
Source Project: spring-analysis-note Source File: MethodJmsListenerEndpoint.java License: MIT License | 5 votes |
@Override protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) { Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set"); MessagingMessageListenerAdapter messageListener = createMessageListenerInstance(); Object bean = getBean(); Method method = getMethod(); Assert.state(bean != null && method != null, "No bean+method set on endpoint"); InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(bean, method); messageListener.setHandlerMethod(invocableHandlerMethod); String responseDestination = getDefaultResponseDestination(); if (StringUtils.hasText(responseDestination)) { if (container.isReplyPubSubDomain()) { messageListener.setDefaultResponseTopicName(responseDestination); } else { messageListener.setDefaultResponseQueueName(responseDestination); } } QosSettings responseQosSettings = container.getReplyQosSettings(); if (responseQosSettings != null) { messageListener.setResponseQosSettings(responseQosSettings); } MessageConverter messageConverter = container.getMessageConverter(); if (messageConverter != null) { messageListener.setMessageConverter(messageConverter); } DestinationResolver destinationResolver = container.getDestinationResolver(); if (destinationResolver != null) { messageListener.setDestinationResolver(destinationResolver); } return messageListener; }
Example 13
Source Project: spring-analysis-note Source File: JmsListenerEndpointTests.java License: MIT License | 5 votes |
@Test public void setupMessageContainerUnsupportedContainer() { MessageListenerContainer container = mock(MessageListenerContainer.class); SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint(); endpoint.setMessageListener(new MessageListenerAdapter()); assertThatIllegalArgumentException().isThrownBy(() -> endpoint.setupListenerContainer(container)); }
Example 14
Source Project: spring-analysis-note Source File: MethodJmsListenerEndpointTests.java License: MIT License | 5 votes |
private MessagingMessageListenerAdapter createInstance( DefaultMessageHandlerMethodFactory factory, Method method, MessageListenerContainer container) { MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint(); endpoint.setBean(this.sample); endpoint.setMethod(method); endpoint.setMessageHandlerMethodFactory(factory); return endpoint.createMessageListener(container); }
Example 15
Source Project: java-technology-stack Source File: AbstractJmsListenerEndpoint.java License: MIT License | 5 votes |
@Override public void setupListenerContainer(MessageListenerContainer listenerContainer) { if (listenerContainer instanceof AbstractMessageListenerContainer) { setupJmsListenerContainer((AbstractMessageListenerContainer) listenerContainer); } else { new JcaEndpointConfigurer().configureEndpoint(listenerContainer); } }
Example 16
Source Project: java-technology-stack Source File: JmsListenerEndpointRegistry.java License: MIT License | 5 votes |
@Override public void stop(Runnable callback) { Collection<MessageListenerContainer> listenerContainers = getListenerContainers(); AggregatingCallback aggregatingCallback = new AggregatingCallback(listenerContainers.size(), callback); for (MessageListenerContainer listenerContainer : listenerContainers) { listenerContainer.stop(aggregatingCallback); } }
Example 17
Source Project: java-technology-stack Source File: JmsListenerEndpointRegistry.java License: MIT License | 5 votes |
@Override public boolean isRunning() { for (MessageListenerContainer listenerContainer : getListenerContainers()) { if (listenerContainer.isRunning()) { return true; } } return false; }
Example 18
Source Project: java-technology-stack Source File: JmsListenerEndpointRegistry.java License: MIT License | 5 votes |
@Override public void destroy() { for (MessageListenerContainer listenerContainer : getListenerContainers()) { if (listenerContainer instanceof DisposableBean) { try { ((DisposableBean) listenerContainer).destroy(); } catch (Throwable ex) { logger.warn("Failed to destroy message listener container", ex); } } } }
Example 19
Source Project: java-technology-stack Source File: MethodJmsListenerEndpoint.java License: MIT License | 5 votes |
@Override protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) { Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set"); MessagingMessageListenerAdapter messageListener = createMessageListenerInstance(); InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod()); messageListener.setHandlerMethod(invocableHandlerMethod); String responseDestination = getDefaultResponseDestination(); if (StringUtils.hasText(responseDestination)) { if (container.isReplyPubSubDomain()) { messageListener.setDefaultResponseTopicName(responseDestination); } else { messageListener.setDefaultResponseQueueName(responseDestination); } } QosSettings responseQosSettings = container.getReplyQosSettings(); if (responseQosSettings != null) { messageListener.setResponseQosSettings(responseQosSettings); } MessageConverter messageConverter = container.getMessageConverter(); if (messageConverter != null) { messageListener.setMessageConverter(messageConverter); } DestinationResolver destinationResolver = container.getDestinationResolver(); if (destinationResolver != null) { messageListener.setDestinationResolver(destinationResolver); } return messageListener; }
Example 20
Source Project: java-technology-stack Source File: JmsListenerEndpointTests.java License: MIT License | 5 votes |
@Test public void setupMessageContainerUnsupportedContainer() { MessageListenerContainer container = mock(MessageListenerContainer.class); SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint(); endpoint.setMessageListener(new MessageListenerAdapter()); thrown.expect(IllegalArgumentException.class); endpoint.setupListenerContainer(container); }
Example 21
Source Project: java-technology-stack Source File: MethodJmsListenerEndpointTests.java License: MIT License | 5 votes |
private MessagingMessageListenerAdapter createInstance( DefaultMessageHandlerMethodFactory factory, Method method, MessageListenerContainer container) { MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint(); endpoint.setBean(this.sample); endpoint.setMethod(method); endpoint.setMessageHandlerMethodFactory(factory); return endpoint.createMessageListener(container); }
Example 22
Source Project: spring4-understanding Source File: AbstractJmsListenerEndpoint.java License: Apache License 2.0 | 5 votes |
@Override public void setupListenerContainer(MessageListenerContainer listenerContainer) { if (listenerContainer instanceof AbstractMessageListenerContainer) { setupJmsListenerContainer((AbstractMessageListenerContainer) listenerContainer); } else { new JcaEndpointConfigurer().configureEndpoint(listenerContainer); } }
Example 23
Source Project: spring4-understanding Source File: JmsListenerEndpointRegistry.java License: Apache License 2.0 | 5 votes |
@Override public void destroy() { for (MessageListenerContainer listenerContainer : getListenerContainers()) { if (listenerContainer instanceof DisposableBean) { try { ((DisposableBean) listenerContainer).destroy(); } catch (Throwable ex) { logger.warn("Failed to destroy message listener container", ex); } } } }
Example 24
Source Project: spring4-understanding Source File: JmsListenerEndpointRegistry.java License: Apache License 2.0 | 5 votes |
@Override public void stop(Runnable callback) { Collection<MessageListenerContainer> listenerContainers = getListenerContainers(); AggregatingCallback aggregatingCallback = new AggregatingCallback(listenerContainers.size(), callback); for (MessageListenerContainer listenerContainer : listenerContainers) { listenerContainer.stop(aggregatingCallback); } }
Example 25
Source Project: spring4-understanding Source File: JmsListenerEndpointRegistry.java License: Apache License 2.0 | 5 votes |
@Override public boolean isRunning() { for (MessageListenerContainer listenerContainer : getListenerContainers()) { if (listenerContainer.isRunning()) { return true; } } return false; }
Example 26
Source Project: spring4-understanding Source File: MethodJmsListenerEndpoint.java License: Apache License 2.0 | 5 votes |
@Override protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) { Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set"); MessagingMessageListenerAdapter messageListener = createMessageListenerInstance(); InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod()); messageListener.setHandlerMethod(invocableHandlerMethod); String responseDestination = getDefaultResponseDestination(); if (StringUtils.hasText(responseDestination)) { if (container.isReplyPubSubDomain()) { messageListener.setDefaultResponseTopicName(responseDestination); } else { messageListener.setDefaultResponseQueueName(responseDestination); } } MessageConverter messageConverter = container.getMessageConverter(); if (messageConverter != null) { messageListener.setMessageConverter(messageConverter); } DestinationResolver destinationResolver = container.getDestinationResolver(); if (destinationResolver != null) { messageListener.setDestinationResolver(destinationResolver); } return messageListener; }
Example 27
Source Project: spring4-understanding Source File: JmsListenerEndpointTests.java License: Apache License 2.0 | 5 votes |
@Test public void setupMessageContainerUnsupportedContainer() { MessageListenerContainer container = mock(MessageListenerContainer.class); SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint(); endpoint.setMessageListener(new MessageListenerAdapter()); thrown.expect(IllegalArgumentException.class); endpoint.setupListenerContainer(container); }
Example 28
Source Project: spring4-understanding Source File: MethodJmsListenerEndpointTests.java License: Apache License 2.0 | 5 votes |
private MessagingMessageListenerAdapter createInstance( DefaultMessageHandlerMethodFactory factory, Method method, MessageListenerContainer container) { MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint(); endpoint.setBean(sample); endpoint.setMethod(method); endpoint.setMessageHandlerMethodFactory(factory); return endpoint.createMessageListener(container); }
Example 29
Source Project: c2mon Source File: MockServerConfig.java License: GNU Lesser General Public License v3.0 | 5 votes |
@Bean public MessageListenerContainer mockServerListener(ActiveMQConnectionFactory connectionFactory) { DefaultMessageListenerContainer container = new DefaultMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setDestination(new ActiveMQQueue("c2mon.client.request")); container.setMessageListener((SessionAwareMessageListener) (message, session) -> { session.createProducer(message.getJMSReplyTo()).send(session.createTextMessage("[]")); }); return container; }
Example 30
Source Project: spring-cloud-contract Source File: StubRunnerJmsConfiguration.java License: Apache License 2.0 | 5 votes |
private MessageListenerContainer listenerContainer(String queueName, ConnectionFactory connectionFactory, MessageListener listener) { DefaultMessageListenerContainer container = new DefaultMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setDestinationName(queueName); container.setMessageListener(listener); return container; }