Java Code Examples for org.springframework.jms.listener.SimpleMessageListenerContainer

The following examples show how to use org.springframework.jms.listener.SimpleMessageListenerContainer. 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
@Test
public void simpleMessageListener() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, SimpleMessageListenerTestBean.class);

	JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
	assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
	MessageListenerTestContainer container = factory.getListenerContainers().get(0);

	JmsListenerEndpoint endpoint = container.getEndpoint();
	assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
	MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
	assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class),
			methodEndpoint.getMethod());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class),
			methodEndpoint.getMostSpecificMethod());

	SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
	methodEndpoint.setupListenerContainer(listenerContainer);
	assertNotNull(listenerContainer.getMessageListener());

	assertTrue("Should have been started " + container, container.isStarted());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example 2
@Test
public void createSimpleContainer() {
	SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
	setDefaultJmsConfig(factory);
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();

	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");

	SimpleMessageListenerContainer container = factory.createListenerContainer(endpoint);

	assertDefaultJmsConfig(container);
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getDestinationName());
}
 
Example 3
@Test
public void simpleMessageListener() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, SimpleMessageListenerTestBean.class);

	JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
	assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
	MessageListenerTestContainer container = factory.getListenerContainers().get(0);

	JmsListenerEndpoint endpoint = container.getEndpoint();
	assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
	MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
	assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class),
			methodEndpoint.getMethod());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class),
			methodEndpoint.getMostSpecificMethod());

	SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
	methodEndpoint.setupListenerContainer(listenerContainer);
	assertNotNull(listenerContainer.getMessageListener());

	assertTrue("Should have been started " + container, container.isStarted());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example 4
@Test
public void createSimpleContainer() {
	SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
	setDefaultJmsConfig(factory);
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();

	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");

	SimpleMessageListenerContainer container = factory.createListenerContainer(endpoint);

	assertDefaultJmsConfig(container);
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getDestinationName());
}
 
Example 5
@Test
public void simpleMessageListener() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, SimpleMessageListenerTestBean.class);

	JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
	assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
	MessageListenerTestContainer container = factory.getListenerContainers().get(0);

	JmsListenerEndpoint endpoint = container.getEndpoint();
	assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
	MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
	assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());

	SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
	methodEndpoint.setupListenerContainer(listenerContainer);
	assertNotNull(listenerContainer.getMessageListener());

	assertTrue("Should have been started " + container, container.isStarted());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example 6
@Test
public void createSimpleContainer() {
	SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
	setDefaultJmsConfig(factory);
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();

	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");

	SimpleMessageListenerContainer container = factory.createListenerContainer(endpoint);

	assertDefaultJmsConfig(container);
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getDestinationName());
}
 
Example 7
/**
 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
 *
 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
 */
public void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();

	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	endpoint.setupListenerContainer(container);
	MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
	listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
 
Example 8
Source Project: spring-analysis-note   Source File: JmsListenerEndpointTests.java    License: MIT License 5 votes vote down vote up
@Test
public void setupConcurrencySimpleContainer() {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setConcurrency("5-10"); // simple implementation only support max value
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	assertEquals(10, new DirectFieldAccessor(container).getPropertyValue("concurrentConsumers"));
}
 
Example 9
@Test
public void processAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 10
@Test
public void processFromTopicAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setPubSubDomain(true);
	container.setReplyPubSubDomain(false);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 11
@Test
public void processAndReplyWithSendToTopic() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setPubSubDomain(true);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", true);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 12
@Test
public void processFromQueueAndReplyWithSendToTopic() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setReplyPubSubDomain(true);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", true);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 13
@Test
public void processAndReplyWithCustomReplyQosSettings() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	QosSettings replyQosSettings = new QosSettings(1, 6, 6000);
	container.setReplyQosSettings(replyQosSettings);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false, replyQosSettings);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 14
@Test
public void processAndReplyWithNullReplyQosSettings() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setReplyQosSettings(null);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 15
/**
 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
 *
 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
 */
public void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();

	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	endpoint.setupListenerContainer(container);
	MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
	listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
 
Example 16
Source Project: java-technology-stack   Source File: JmsListenerEndpointTests.java    License: MIT License 5 votes vote down vote up
@Test
public void setupConcurrencySimpleContainer() {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setConcurrency("5-10"); // simple implementation only support max value
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	assertEquals(10, new DirectFieldAccessor(container).getPropertyValue("concurrentConsumers"));
}
 
Example 17
@Test
public void processAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 18
@Test
public void processFromTopicAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setPubSubDomain(true);
	container.setReplyPubSubDomain(false);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 19
@Test
public void processAndReplyWithSendToTopic() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setPubSubDomain(true);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", true);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 20
@Test
public void processFromQueueAndReplyWithSendToTopic() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setReplyPubSubDomain(true);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", true);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 21
@Test
public void processAndReplyWithCustomReplyQosSettings() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	QosSettings replyQosSettings = new QosSettings(1, 6, 6000);
	container.setReplyQosSettings(replyQosSettings);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false, replyQosSettings);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 22
@Test
public void processAndReplyWithNullReplyQosSettings() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setReplyQosSettings(null);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 23
Source Project: spring-jms   Source File: ReceiverConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public SimpleMessageListenerContainer statusMessageListenerContainer() {
  SimpleJmsListenerEndpoint endpoint =
      new SimpleJmsListenerEndpoint();
  endpoint.setMessageListener(new StatusMessageListener("SMLC"));
  endpoint.setDestination(status2Destination);

  return orderSimpleJmsListenerContainerFactory()
      .createListenerContainer(endpoint);
}
 
Example 24
Source Project: spring-jms   Source File: InboundGatewayConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer(
    ConnectionFactory connectionFactory) {
  SimpleMessageListenerContainer container =
      new SimpleMessageListenerContainer();
  container.setConnectionFactory(connectionFactory);
  container.setDestinationName(orderRequestDestination);
  return container;
}
 
Example 25
Source Project: spring-jms   Source File: ConsumingChannelConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer(
    ConnectionFactory connectionFactory) {
  SimpleMessageListenerContainer container =
      new SimpleMessageListenerContainer();
  container.setConnectionFactory(connectionFactory);
  container.setDestinationName(integrationDestination);
  return container;
}
 
Example 26
/**
 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
 *
 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
 */
public void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();

	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	endpoint.setupListenerContainer(container);
	MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
	listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
 
Example 27
@Test
public void setupConcurrencySimpleContainer() {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setConcurrency("5-10"); // simple implementation only support max value
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	assertEquals(10, new DirectFieldAccessor(container).getPropertyValue("concurrentConsumers"));
}
 
Example 28
@Test
public void processAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, false);
	assertListenerMethodInvocation(sample, methodName);
}
 
Example 29
@Test
public void processFromTopicAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setPubSubDomain(true);
	container.setReplyPubSubDomain(false);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, false);
	assertListenerMethodInvocation(sample, methodName);
}
 
Example 30
@Test
public void processAndReplyWithSendToTopic() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setPubSubDomain(true);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, true);
	assertListenerMethodInvocation(sample, methodName);
}