org.springframework.jms.listener.adapter.MessageListenerAdapter Java Examples

The following examples show how to use org.springframework.jms.listener.adapter.MessageListenerAdapter. 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 File: JmsListenerContainerFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void createJcaContainerFullConfig() {
	DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
	setDefaultJcaConfig(factory);
	factory.setConcurrency("10");

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	JmsMessageEndpointManager container = factory.createListenerContainer(endpoint);

	assertDefaultJcaConfig(container);
	assertEquals(10, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getActivationSpecConfig().getDestinationName());
}
 
Example #2
Source File: JmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void setupJcaMessageContainerFullConfig() {
	JmsMessageEndpointManager container = new JmsMessageEndpointManager();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertEquals("myQueue", config.getDestinationName());
	assertEquals("foo = 'bar'", config.getMessageSelector());
	assertEquals("mySubscription", config.getSubscriptionName());
	assertEquals(10, config.getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #3
Source File: JmsListenerEndpointTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void setupJcaMessageContainerFullConfig() {
	JmsMessageEndpointManager container = new JmsMessageEndpointManager();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertEquals("myQueue", config.getDestinationName());
	assertEquals("foo = 'bar'", config.getMessageSelector());
	assertEquals("mySubscription", config.getSubscriptionName());
	assertEquals(10, config.getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #4
Source File: JmsListenerEndpointTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void setupJmsMessageContainerFullConfig() {
	DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("5-10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	assertEquals("myQueue", container.getDestinationName());
	assertEquals("foo = 'bar'", container.getMessageSelector());
	assertEquals("mySubscription", container.getSubscriptionName());
	assertEquals(5, container.getConcurrentConsumers());
	assertEquals(10, container.getMaxConcurrentConsumers());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #5
Source File: JmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void setupJmsMessageContainerFullConfig() {
	DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("5-10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	assertEquals("myQueue", container.getDestinationName());
	assertEquals("foo = 'bar'", container.getMessageSelector());
	assertEquals("mySubscription", container.getSubscriptionName());
	assertEquals(5, container.getConcurrentConsumers());
	assertEquals(10, container.getMaxConcurrentConsumers());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #6
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testJcaContainerConfiguration() throws Exception {
	Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);

	assertTrue("listener3 not found", containers.containsKey("listener3"));
	JmsMessageEndpointManager listener3 = containers.get("listener3");
	assertEquals("Wrong resource adapter",
			context.getBean("testResourceAdapter"), listener3.getResourceAdapter());
	assertEquals("Wrong activation spec factory", context.getBean("testActivationSpecFactory"),
			new DirectFieldAccessor(listener3).getPropertyValue("activationSpecFactory"));


	Object endpointFactory = new DirectFieldAccessor(listener3).getPropertyValue("endpointFactory");
	Object messageListener = new DirectFieldAccessor(endpointFactory).getPropertyValue("messageListener");
	assertEquals("Wrong message listener", MessageListenerAdapter.class, messageListener.getClass());
	MessageListenerAdapter adapter = (MessageListenerAdapter) messageListener;
	DirectFieldAccessor adapterFieldAccessor = new DirectFieldAccessor(adapter);
	assertEquals("Message converter not set properly", context.getBean("testMessageConverter"),
			adapterFieldAccessor.getPropertyValue("messageConverter"));
	assertEquals("Wrong delegate", context.getBean("testBean1"),
			adapterFieldAccessor.getPropertyValue("delegate"));
	assertEquals("Wrong method name", "setName",
			adapterFieldAccessor.getPropertyValue("defaultListenerMethod"));
}
 
Example #7
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testJcaContainerConfiguration() throws Exception {
	Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);

	assertTrue("listener3 not found", containers.containsKey("listener3"));
	JmsMessageEndpointManager listener3 = containers.get("listener3");
	assertEquals("Wrong resource adapter",
			context.getBean("testResourceAdapter"), listener3.getResourceAdapter());
	assertEquals("Wrong activation spec factory", context.getBean("testActivationSpecFactory"),
			new DirectFieldAccessor(listener3).getPropertyValue("activationSpecFactory"));


	Object endpointFactory = new DirectFieldAccessor(listener3).getPropertyValue("endpointFactory");
	Object messageListener = new DirectFieldAccessor(endpointFactory).getPropertyValue("messageListener");
	assertEquals("Wrong message listener", MessageListenerAdapter.class, messageListener.getClass());
	MessageListenerAdapter adapter = (MessageListenerAdapter) messageListener;
	DirectFieldAccessor adapterFieldAccessor = new DirectFieldAccessor(adapter);
	assertEquals("Message converter not set properly", context.getBean("testMessageConverter"),
			adapterFieldAccessor.getPropertyValue("messageConverter"));
	assertEquals("Wrong delegate", context.getBean("testBean1"),
			adapterFieldAccessor.getPropertyValue("delegate"));
	assertEquals("Wrong method name", "setName",
			adapterFieldAccessor.getPropertyValue("defaultListenerMethod"));
}
 
Example #8
Source File: JmsListenerContainerFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 #9
Source File: JmsListenerContainerFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: JmsListenerContainerFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void createJmsContainerFullConfig() {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	setDefaultJmsConfig(factory);
	factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
	factory.setConcurrency("3-10");
	factory.setMaxMessagesPerTask(5);

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);

	assertDefaultJmsConfig(container);
	assertEquals(DefaultMessageListenerContainer.CACHE_CONSUMER, container.getCacheLevel());
	assertEquals(3, container.getConcurrentConsumers());
	assertEquals(10, container.getMaxConcurrentConsumers());
	assertEquals(5, container.getMaxMessagesPerTask());

	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getDestinationName());
}
 
Example #11
Source File: JmsListenerContainerFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void createJmsContainerFullConfig() {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	setDefaultJmsConfig(factory);
	factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
	factory.setConcurrency("3-10");
	factory.setMaxMessagesPerTask(5);

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);

	assertDefaultJmsConfig(container);
	assertEquals(DefaultMessageListenerContainer.CACHE_CONSUMER, container.getCacheLevel());
	assertEquals(3, container.getConcurrentConsumers());
	assertEquals(10, container.getMaxConcurrentConsumers());
	assertEquals(5, container.getMaxMessagesPerTask());

	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getDestinationName());
}
 
Example #12
Source File: JmsListenerContainerFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 #13
Source File: JmsListenerContainerFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void createJcaContainerFullConfig() {
	DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
	setDefaultJcaConfig(factory);
	factory.setConcurrency("10");

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	JmsMessageEndpointManager container = factory.createListenerContainer(endpoint);

	assertDefaultJcaConfig(container);
	assertEquals(10, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getActivationSpecConfig().getDestinationName());
}
 
Example #14
Source File: JmsListenerContainerFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void createJmsContainerFullConfig() {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	setDefaultJmsConfig(factory);
	factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
	factory.setConcurrency("3-10");
	factory.setMaxMessagesPerTask(5);

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);

	assertDefaultJmsConfig(container);
	assertEquals(DefaultMessageListenerContainer.CACHE_CONSUMER, container.getCacheLevel());
	assertEquals(3, container.getConcurrentConsumers());
	assertEquals(10, container.getMaxConcurrentConsumers());
	assertEquals(5, container.getMaxMessagesPerTask());

	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getDestinationName());
}
 
Example #15
Source File: JmsListenerContainerFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void createJcaContainerFullConfig() {
	DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
	setDefaultJcaConfig(factory);
	factory.setConcurrency("10");

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	JmsMessageEndpointManager container = factory.createListenerContainer(endpoint);

	assertDefaultJcaConfig(container);
	assertEquals(10, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getActivationSpecConfig().getDestinationName());
}
 
Example #16
Source File: JmsListenerEndpointTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void setupJcaMessageContainerFullConfig() {
	JmsMessageEndpointManager container = new JmsMessageEndpointManager();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertEquals("myQueue", config.getDestinationName());
	assertEquals("foo = 'bar'", config.getMessageSelector());
	assertEquals("mySubscription", config.getSubscriptionName());
	assertEquals(10, config.getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #17
Source File: JmsListenerEndpointTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void setupJmsMessageContainerFullConfig() {
	DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("5-10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	assertEquals("myQueue", container.getDestinationName());
	assertEquals("foo = 'bar'", container.getMessageSelector());
	assertEquals("mySubscription", container.getSubscriptionName());
	assertEquals(5, container.getConcurrentConsumers());
	assertEquals(10, container.getMaxConcurrentConsumers());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #18
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testJcaContainerConfiguration() throws Exception {
	Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);

	assertTrue("listener3 not found", containers.containsKey("listener3"));
	JmsMessageEndpointManager listener3 = containers.get("listener3");
	assertEquals("Wrong resource adapter",
			context.getBean("testResourceAdapter"), listener3.getResourceAdapter());
	assertEquals("Wrong activation spec factory", context.getBean("testActivationSpecFactory"),
			new DirectFieldAccessor(listener3).getPropertyValue("activationSpecFactory"));


	Object endpointFactory = new DirectFieldAccessor(listener3).getPropertyValue("endpointFactory");
	Object messageListener = new DirectFieldAccessor(endpointFactory).getPropertyValue("messageListener");
	assertEquals("Wrong message listener", MessageListenerAdapter.class, messageListener.getClass());
	MessageListenerAdapter adapter = (MessageListenerAdapter) messageListener;
	DirectFieldAccessor adapterFieldAccessor = new DirectFieldAccessor(adapter);
	assertEquals("Message converter not set properly", context.getBean("testMessageConverter"),
			adapterFieldAccessor.getPropertyValue("messageConverter"));
	assertEquals("Wrong delegate", context.getBean("testBean1"),
			adapterFieldAccessor.getPropertyValue("delegate"));
	assertEquals("Wrong method name", "setName",
			adapterFieldAccessor.getPropertyValue("defaultListenerMethod"));
}
 
Example #19
Source File: JmsListenerContainerFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void endpointConcurrencyTakesPrecedence() {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	factory.setConcurrency("2-10");

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	endpoint.setConcurrency("4-6");
	DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);
	assertEquals(4, container.getConcurrentConsumers());
	assertEquals(6, container.getMaxConcurrentConsumers());
}
 
Example #20
Source File: MQHierachy.java    From Thunder with Apache License 2.0 5 votes vote down vote up
public void listen(Destination destination, SessionAwareMessageListener<BytesMessage> messageListener, String requestSelector, boolean topic) throws Exception {
    int concurrentConsumers = mqPropertyEntity.getInteger(ThunderConstant.MQ_CONCURRENT_CONSUMERS_ATTRIBUTE_NAME);
    int maxConcurrentConsumers = mqPropertyEntity.getInteger(ThunderConstant.MQ_MAX_CONCURRENT_CONSUMERS_ATTRIBUTE_NAME);
    long receiveTimeout = mqPropertyEntity.getLong(ThunderConstant.MQ_RECEIVE_TIMEOUT_ATTRIBUTE_NAME);
    long recoveryInterval = mqPropertyEntity.getLong(ThunderConstant.MQ_RECOVERY_INTERVAL_ATTRIBUTE_NAME);
    int idleConsumerLimit = mqPropertyEntity.getInteger(ThunderConstant.MQ_IDLE_CONSUMER_LIMIT_ATTRIBUTE_NAME);
    int idleTaskExecutionLimit = mqPropertyEntity.getInteger(ThunderConstant.MQ_IDLE_TASK_EXECUTION_LIMIT_ATTRIBUTE_NAME);
    int cacheLevel = mqPropertyEntity.getInteger(ThunderConstant.MQ_CACHE_LEVEL_ATTRIBUTE_NAME);
    boolean acceptMessagesWhileStopping = mqPropertyEntity.getBoolean(ThunderConstant.MQ_ACCEPT_MESSAGES_WHILE_STOPPING_ATTRIBUTE_NAME);

    MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter();
    messageListenerAdapter.setDelegate(messageListener);

    DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
    messageListenerContainer.setDestination(destination);
    messageListenerContainer.setConnectionFactory(connectionFactory);
    messageListenerContainer.setMessageListener(messageListenerAdapter);
    if (StringUtils.isNotEmpty(requestSelector)) {
        messageListenerContainer.setMessageSelector(SelectorType.REQUEST_SELECTOR + " = '" + requestSelector + "'");
    }
    messageListenerContainer.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
    messageListenerContainer.setPubSubDomain(topic);
    messageListenerContainer.setConcurrentConsumers(topic ? 1 : concurrentConsumers);
    messageListenerContainer.setMaxConcurrentConsumers(topic ? 1 : maxConcurrentConsumers);
    messageListenerContainer.setReceiveTimeout(receiveTimeout);
    messageListenerContainer.setRecoveryInterval(recoveryInterval);
    messageListenerContainer.setIdleConsumerLimit(idleConsumerLimit);
    messageListenerContainer.setIdleTaskExecutionLimit(idleTaskExecutionLimit);
    messageListenerContainer.setCacheLevel(cacheLevel);
    messageListenerContainer.setAcceptMessagesWhileStopping(acceptMessagesWhileStopping);
    messageListenerContainer.afterPropertiesSet();
    messageListenerContainer.start();
}
 
Example #21
Source File: JmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 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 #22
Source File: JmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: SimpleJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void createListener() {
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	assertSame(messageListener, endpoint.createMessageListener(container));
}
 
Example #24
Source File: JmsListenerContainerFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void jcaExclusiveProperties() {
	DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
	factory.setDestinationResolver(destinationResolver);
	factory.setActivationSpecFactory(new StubJmsActivationSpecFactory());

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setMessageListener(new MessageListenerAdapter());
	thrown.expect(IllegalStateException.class);
	factory.createListenerContainer(endpoint);
}
 
Example #25
Source File: JmsListenerContainerFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void backOffOverridesRecoveryInterval() {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	BackOff backOff = new FixedBackOff();
	factory.setBackOff(backOff);
	factory.setRecoveryInterval(2000L);

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);

	assertSame(backOff, new DirectFieldAccessor(container).getPropertyValue("backOff"));
}
 
Example #26
Source File: JmsMessageBrokerConfiguration.java    From piper with Apache License 2.0 5 votes vote down vote up
private void registerListenerEndpoint(JmsListenerEndpointRegistrar aRegistrar, String aQueueName, int aConcurrency, Object aDelegate, String aMethodName) {
  logger.info("Registring JMS Listener: {} -> {}:{}", aQueueName, aDelegate.getClass().getName(), aMethodName);
  
  MessageListenerAdapter messageListener = new NoReplyMessageListenerAdapter(aDelegate);
  messageListener.setMessageConverter(jacksonJmsMessageConverter(objectMapper));
  messageListener.setDefaultListenerMethod(aMethodName);

  SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
  endpoint.setId(aQueueName+"Endpoint");
  endpoint.setDestination(aQueueName);
  endpoint.setMessageListener(messageListener);

  aRegistrar.registerEndpoint(endpoint,createContainerFactory(aConcurrency));
}
 
Example #27
Source File: JmsListenerContainerFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void jcaExclusiveProperties() {
	DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
	factory.setDestinationResolver(this.destinationResolver);
	factory.setActivationSpecFactory(new StubJmsActivationSpecFactory());

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setMessageListener(new MessageListenerAdapter());
	this.thrown.expect(IllegalStateException.class);
	factory.createListenerContainer(endpoint);
}
 
Example #28
Source File: JmsListenerContainerFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void backOffOverridesRecoveryInterval() {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	BackOff backOff = new FixedBackOff();
	factory.setBackOff(backOff);
	factory.setRecoveryInterval(2000L);

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);

	assertSame(backOff, new DirectFieldAccessor(container).getPropertyValue("backOff"));
}
 
Example #29
Source File: SimpleJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void createListener() {
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	assertSame(messageListener, endpoint.createMessageListener(container));
}
 
Example #30
Source File: JmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void setupMessageContainerUnsupportedContainer() {
	MessageListenerContainer container = mock(MessageListenerContainer.class);
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setMessageListener(new MessageListenerAdapter());

	thrown.expect(IllegalArgumentException.class);
	endpoint.setupListenerContainer(container);
}