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

The following examples show how to use org.springframework.jms.listener.DefaultMessageListenerContainer. 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: c2mon   Author: c2mon   File: AdminJmsConfig.java    License: GNU Lesser General Public License v3.0 7 votes vote down vote up
@Bean
public DefaultMessageListenerContainer adminRequestJmsContainer(ClientRequestDelegator delegator, ClientRequestErrorHandler errorHandler) {
  DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();

  String adminRequestQueue = properties.getJms().getAdminRequestQueue();
  container.setDestination(new ActiveMQQueue(adminRequestQueue));

  container.setConnectionFactory(adminSingleConnectionFactory());
  container.setMessageListener(delegator);
  container.setConcurrentConsumers(1);
  container.setMaxConcurrentConsumers(2);
  container.setMaxMessagesPerTask(1);
  container.setReceiveTimeout(1000);
  container.setIdleTaskExecutionLimit(600);
  container.setSessionTransacted(false);
  container.setTaskExecutor(clientExecutor);
  container.setErrorHandler(errorHandler);
  container.setAutoStartup(false);
  container.setPhase(ServerConstants.PHASE_INTERMEDIATE);
  return container;
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testContainerConfiguration() throws Exception {
	Map<String, DefaultMessageListenerContainer> containers = context.getBeansOfType(DefaultMessageListenerContainer.class);
	ConnectionFactory defaultConnectionFactory = context.getBean(DEFAULT_CONNECTION_FACTORY, ConnectionFactory.class);
	ConnectionFactory explicitConnectionFactory = context.getBean(EXPLICIT_CONNECTION_FACTORY, ConnectionFactory.class);

	int defaultConnectionFactoryCount = 0;
	int explicitConnectionFactoryCount = 0;

	for (DefaultMessageListenerContainer container : containers.values()) {
		if (container.getConnectionFactory().equals(defaultConnectionFactory)) {
			defaultConnectionFactoryCount++;
		}
		else if (container.getConnectionFactory().equals(explicitConnectionFactory)) {
			explicitConnectionFactoryCount++;
		}
	}

	assertEquals("1 container should have the default connectionFactory", 1, defaultConnectionFactoryCount);
	assertEquals("2 containers should have the explicit connectionFactory", 2, explicitConnectionFactoryCount);
}
 
Example #3
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testJmsContainerFactoryConfiguration() {
	Map<String, DefaultJmsListenerContainerFactory> containers =
			context.getBeansOfType(DefaultJmsListenerContainerFactory.class);
	DefaultJmsListenerContainerFactory factory = containers.get("testJmsFactory");
	assertNotNull("No factory registered with testJmsFactory id", factory);

	DefaultMessageListenerContainer container =
			factory.createListenerContainer(createDummyEndpoint());
	assertEquals("explicit connection factory not set",
			context.getBean(EXPLICIT_CONNECTION_FACTORY), container.getConnectionFactory());
	assertEquals("explicit destination resolver not set",
			context.getBean("testDestinationResolver"), container.getDestinationResolver());
	assertEquals("explicit message converter not set",
			context.getBean("testMessageConverter"), container.getMessageConverter());
	assertEquals("Wrong pub/sub", true, container.isPubSubDomain());
	assertEquals("Wrong durable flag", true, container.isSubscriptionDurable());
	assertEquals("wrong cache", DefaultMessageListenerContainer.CACHE_CONNECTION, container.getCacheLevel());
	assertEquals("wrong concurrency", 3, container.getConcurrentConsumers());
	assertEquals("wrong concurrency", 5, container.getMaxConcurrentConsumers());
	assertEquals("wrong prefetch", 50, container.getMaxMessagesPerTask());
	assertEquals("Wrong phase", 99, container.getPhase());
	assertSame(context.getBean("testBackOff"), new DirectFieldAccessor(container).getPropertyValue("backOff"));
}
 
Example #4
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testResponseDestination() {
	// JMS
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);
	assertEquals("Wrong destination type on listener1", true, listener1.isPubSubDomain());
	assertEquals("Wrong destination type on listener2", true, listener2.isPubSubDomain());
	assertEquals("Wrong response destination type on listener1", false, listener1.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener2", false, listener2.isReplyPubSubDomain());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong destination type on listener3", true, listener3.isPubSubDomain());
	assertEquals("Wrong destination type on listener4", true, listener4.isPubSubDomain());
	assertEquals("Wrong response destination type on listener3", false, listener3.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener4", false, listener4.isReplyPubSubDomain());
}
 
Example #5
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testComponentRegistration() {
	assertTrue("Parser should have registered a component named 'listener1'",
			context.containsComponentDefinition("listener1"));
	assertTrue("Parser should have registered a component named 'listener2'",
			context.containsComponentDefinition("listener2"));
	assertTrue("Parser should have registered a component named 'listener3'",
			context.containsComponentDefinition("listener3"));
	assertTrue("Parser should have registered a component named '"
			+ DefaultMessageListenerContainer.class.getName() + "#0'",
			context.containsComponentDefinition(DefaultMessageListenerContainer.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named '"
			+ JmsMessageEndpointManager.class.getName() + "#0'",
			context.containsComponentDefinition(JmsMessageEndpointManager.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named 'testJmsFactory",
			context.containsComponentDefinition("testJmsFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("testJcaFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("onlyJmsFactory"));
}
 
Example #6
Source Project: c2mon   Author: c2mon   File: JmsContainerManagerImpl.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
  clusterCache.acquireWriteLockOnKey(CONFIG_LOCK_KEY);
  try {
    LOGGER.debug("Checking JMS subscriptions are up to date.");
    try {
      //check no new
      for (Long id : processCache.getKeys()) {
        if (!jmsContainers.containsKey(id)) {
          subscribe(processCache.get(id));
        }
      }
      //check no old that needs unsubscribing
      for (Map.Entry<Long, DefaultMessageListenerContainer> entry : jmsContainers.entrySet()) {
        if (!processCache.getKeys().contains(entry.getKey())) {
          unsubscribe(entry.getKey());
        }
      }
    } catch (Exception e) {
      LOGGER.error("Unexpected exception caught while updating Process JMS containers", e);
    }
  } finally {
    clusterCache.releaseWriteLockOnKey(CONFIG_LOCK_KEY);
  }
}
 
Example #7
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsListenerEndpointTests.java    License: 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 #8
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsListenerContainerFactoryTests.java    License: 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 #9
Source Project: java-technology-stack   Author: codeEngraver   File: JmsNamespaceHandlerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testContainerConfiguration() throws Exception {
	Map<String, DefaultMessageListenerContainer> containers = context.getBeansOfType(DefaultMessageListenerContainer.class);
	ConnectionFactory defaultConnectionFactory = context.getBean(DEFAULT_CONNECTION_FACTORY, ConnectionFactory.class);
	ConnectionFactory explicitConnectionFactory = context.getBean(EXPLICIT_CONNECTION_FACTORY, ConnectionFactory.class);

	int defaultConnectionFactoryCount = 0;
	int explicitConnectionFactoryCount = 0;

	for (DefaultMessageListenerContainer container : containers.values()) {
		if (container.getConnectionFactory().equals(defaultConnectionFactory)) {
			defaultConnectionFactoryCount++;
		}
		else if (container.getConnectionFactory().equals(explicitConnectionFactory)) {
			explicitConnectionFactoryCount++;
		}
	}

	assertEquals("1 container should have the default connectionFactory", 1, defaultConnectionFactoryCount);
	assertEquals("2 containers should have the explicit connectionFactory", 2, explicitConnectionFactoryCount);
}
 
Example #10
Source Project: c2mon   Author: c2mon   File: ClientJmsConfig.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Bean
public DefaultMessageListenerContainer clientRequestJmsContainer(ClientRequestDelegator delegator, ClientRequestErrorHandler errorHandler) {
  DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();

  String clientRequestQueue = properties.getJms().getRequestQueue();
  container.setDestination(new ActiveMQQueue(clientRequestQueue));

  container.setConnectionFactory(clientSingleConnectionFactory());
  container.setMessageListener(delegator);
  container.setConcurrentConsumers(properties.getJms().getInitialConsumers());
  container.setMaxConcurrentConsumers(properties.getJms().getMaxConsumers());
  container.setMaxMessagesPerTask(1);
  container.setReceiveTimeout(1000);
  container.setIdleTaskExecutionLimit(600);
  container.setSessionTransacted(false);
  container.setTaskExecutor(clientExecutor());
  container.setErrorHandler(errorHandler);
  container.setAutoStartup(false);
  container.setPhase(ServerConstants.PHASE_INTERMEDIATE);
  return container;
}
 
Example #11
Source Project: java-technology-stack   Author: codeEngraver   File: JmsNamespaceHandlerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testResponseDestination() {
	// JMS
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);
	assertEquals("Wrong destination type on listener1", true, listener1.isPubSubDomain());
	assertEquals("Wrong destination type on listener2", true, listener2.isPubSubDomain());
	assertEquals("Wrong response destination type on listener1", false, listener1.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener2", false, listener2.isReplyPubSubDomain());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong destination type on listener3", true, listener3.isPubSubDomain());
	assertEquals("Wrong destination type on listener4", true, listener4.isPubSubDomain());
	assertEquals("Wrong response destination type on listener3", false, listener3.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener4", false, listener4.isReplyPubSubDomain());
}
 
Example #12
Source Project: java-technology-stack   Author: codeEngraver   File: JmsNamespaceHandlerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testComponentRegistration() {
	assertTrue("Parser should have registered a component named 'listener1'",
			context.containsComponentDefinition("listener1"));
	assertTrue("Parser should have registered a component named 'listener2'",
			context.containsComponentDefinition("listener2"));
	assertTrue("Parser should have registered a component named 'listener3'",
			context.containsComponentDefinition("listener3"));
	assertTrue("Parser should have registered a component named '"
			+ DefaultMessageListenerContainer.class.getName() + "#0'",
			context.containsComponentDefinition(DefaultMessageListenerContainer.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named '"
			+ JmsMessageEndpointManager.class.getName() + "#0'",
			context.containsComponentDefinition(JmsMessageEndpointManager.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named 'testJmsFactory",
			context.containsComponentDefinition("testJmsFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("testJcaFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("onlyJmsFactory"));
}
 
Example #13
Source Project: oneops   Author: oneops   File: Listener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * init - configuration / defaults
 */
public void init() {
  dataDir = new File(config.getDataDir());
  checkFreeSpace();
  logger.info(this);

  Runtime.getRuntime().addShutdownHook(new Thread(() -> {
    DefaultMessageListenerContainer listenerContainer = (DefaultMessageListenerContainer) applicationContext
        .getBean("listenerContainer");
    logger.info("Stopping listener container...");
    listenerContainer.stop();
    while (activeThreads.get() > 0) {
      logger.info("Shutdown in progress. sleeping for 10sec. activeThreads: " + activeThreads);
      try {
        Thread.sleep(10000);
      } catch (InterruptedException e) {
        logger.info("Got InterruptedException, but will still let the activeThreads complete.");
      }
    }
    logger.info("Shutdown done.");
  }));

  File testDir = new File(dataDir, "../test");
  logger.info("Verification test directory created: " + testDir.mkdirs());
}
 
Example #14
Source Project: spring4-understanding   Author: langtianya   File: JmsNamespaceHandlerTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testContainerConfiguration() throws Exception {
	Map<String, DefaultMessageListenerContainer> containers = context.getBeansOfType(DefaultMessageListenerContainer.class);
	ConnectionFactory defaultConnectionFactory = context.getBean(DEFAULT_CONNECTION_FACTORY, ConnectionFactory.class);
	ConnectionFactory explicitConnectionFactory = context.getBean(EXPLICIT_CONNECTION_FACTORY, ConnectionFactory.class);

	int defaultConnectionFactoryCount = 0;
	int explicitConnectionFactoryCount = 0;

	for (DefaultMessageListenerContainer container : containers.values()) {
		if (container.getConnectionFactory().equals(defaultConnectionFactory)) {
			defaultConnectionFactoryCount++;
		}
		else if (container.getConnectionFactory().equals(explicitConnectionFactory)) {
			explicitConnectionFactoryCount++;
		}
	}

	assertEquals("1 container should have the default connectionFactory", 1, defaultConnectionFactoryCount);
	assertEquals("2 containers should have the explicit connectionFactory", 2, explicitConnectionFactoryCount);
}
 
Example #15
Source Project: spring4-understanding   Author: langtianya   File: JmsNamespaceHandlerTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJmsContainerFactoryConfiguration() {
	Map<String, DefaultJmsListenerContainerFactory> containers =
			context.getBeansOfType(DefaultJmsListenerContainerFactory.class);
	DefaultJmsListenerContainerFactory factory = containers.get("testJmsFactory");
	assertNotNull("No factory registered with testJmsFactory id", factory);

	DefaultMessageListenerContainer container =
			factory.createListenerContainer(createDummyEndpoint());
	assertEquals("explicit connection factory not set",
			context.getBean(EXPLICIT_CONNECTION_FACTORY), container.getConnectionFactory());
	assertEquals("explicit destination resolver not set",
			context.getBean("testDestinationResolver"), container.getDestinationResolver());
	assertEquals("explicit message converter not set",
			context.getBean("testMessageConverter"), container.getMessageConverter());
	assertEquals("Wrong pub/sub", true, container.isPubSubDomain());
	assertEquals("Wrong durable flag", true, container.isSubscriptionDurable());
	assertEquals("wrong cache", DefaultMessageListenerContainer.CACHE_CONNECTION, container.getCacheLevel());
	assertEquals("wrong concurrency", 3, container.getConcurrentConsumers());
	assertEquals("wrong concurrency", 5, container.getMaxConcurrentConsumers());
	assertEquals("wrong prefetch", 50, container.getMaxMessagesPerTask());
	assertEquals("Wrong phase", 99, container.getPhase());
	assertSame(context.getBean("testBackOff"), new DirectFieldAccessor(container).getPropertyValue("backOff"));
}
 
Example #16
Source Project: spring4-understanding   Author: langtianya   File: JmsNamespaceHandlerTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseDestination() {
	// JMS
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);
	assertEquals("Wrong destination type on listener1", true, listener1.isPubSubDomain());
	assertEquals("Wrong destination type on listener2", true, listener2.isPubSubDomain());
	assertEquals("Wrong response destination type on listener1", false, listener1.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener2", false, listener2.isReplyPubSubDomain());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong destination type on listener3", true, listener3.isPubSubDomain());
	assertEquals("Wrong destination type on listener4", true, listener4.isPubSubDomain());
	assertEquals("Wrong response destination type on listener3", false, listener3.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener4", false, listener4.isReplyPubSubDomain());
}
 
Example #17
Source Project: spring4-understanding   Author: langtianya   File: JmsNamespaceHandlerTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testComponentRegistration() {
	assertTrue("Parser should have registered a component named 'listener1'",
			context.containsComponentDefinition("listener1"));
	assertTrue("Parser should have registered a component named 'listener2'",
			context.containsComponentDefinition("listener2"));
	assertTrue("Parser should have registered a component named 'listener3'",
			context.containsComponentDefinition("listener3"));
	assertTrue("Parser should have registered a component named '"
			+ DefaultMessageListenerContainer.class.getName() + "#0'",
			context.containsComponentDefinition(DefaultMessageListenerContainer.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named '"
			+ JmsMessageEndpointManager.class.getName() + "#0'",
			context.containsComponentDefinition(JmsMessageEndpointManager.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named 'testJmsFactory",
			context.containsComponentDefinition("testJmsFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("testJcaFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("onlyJmsFactory"));
}
 
Example #18
Source Project: spring-cloud-stream-app-starters   Author: spring-cloud   File: JmsSourceTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
	AbstractMessageListenerContainer container = TestUtils.getPropertyValue(this.endpoint, "listenerContainer",
			AbstractMessageListenerContainer.class);
	assertThat(container, instanceOf(DefaultMessageListenerContainer.class));
	assertEquals(Session.AUTO_ACKNOWLEDGE, TestUtils.getPropertyValue(container, "sessionAcknowledgeMode"));
	assertTrue(TestUtils.getPropertyValue(container, "sessionTransacted", Boolean.class));
	assertEquals("jmssource.test.queue", TestUtils.getPropertyValue(container, "destination"));
	assertEquals("JMSCorrelationId=foo", TestUtils.getPropertyValue(container, "messageSelector"));
	assertFalse(TestUtils.getPropertyValue(container, "subscriptionDurable", Boolean.class));
	assertFalse(TestUtils.getPropertyValue(container, "subscriptionShared", Boolean.class));
	assertEquals(3, TestUtils.getPropertyValue(container, "concurrentConsumers"));
	assertEquals(4, TestUtils.getPropertyValue(container, "maxConcurrentConsumers"));
	assertFalse(TestUtils.getPropertyValue(container, "pubSubDomain", Boolean.class));

	template.convertAndSend("jmssource.test.queue", "Hello, world!");
	Message<?> received = messageCollector.forChannel(channels.output()).poll(10, TimeUnit.SECONDS);
	assertNotNull(received);
	assertEquals("Hello, world!", received.getPayload());
}
 
Example #19
Source Project: spring4-understanding   Author: langtianya   File: JmsListenerContainerFactoryTests.java    License: 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 #20
Source Project: solace-samples-cloudfoundry-java   Author: SolaceSamples   File: SolaceController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/subscription", method = RequestMethod.POST)
public ResponseEntity<String> addSubscription(@RequestBody SimpleSubscription subscription) {
	String subscriptionTopic = subscription.getSubscription();
	logger.info("Adding a subscription to topic: " + subscriptionTopic);

	if ( this.listenerContainersMap.containsKey(subscriptionTopic) ) {
		// Already subscribed
		logger.error("Already subscribed to topic " + subscriptionTopic);
		return new ResponseEntity<>("{'description': 'Already subscribed'}", HttpStatus.BAD_REQUEST);
	}

	try {
    	DefaultMessageListenerContainer listenercontainer = createListener(subscriptionTopic);
        listenercontainer.start();
        this.listenerContainersMap.put(subscriptionTopic, listenercontainer);
	} catch (Exception e) {
		logger.error("Service Creation failed.", e);
		return new ResponseEntity<>("{'description': '" + e.getMessage() + "'}", HttpStatus.BAD_REQUEST);
	}
	logger.info("Finished Adding a subscription to topic: " + subscriptionTopic);
	return new ResponseEntity<>("{}", HttpStatus.OK);
}
 
Example #21
Source Project: solace-samples-cloudfoundry-java   Author: SolaceSamples   File: SolaceController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/subscription/{subscriptionName}", method = RequestMethod.DELETE)
public ResponseEntity<String> deleteSubscription(@PathVariable("subscriptionName") String subscriptionTopic) {
	logger.info("Deleting a subscription to topic: " + subscriptionTopic);

	if ( !this.listenerContainersMap.containsKey(subscriptionTopic) ) {
		// Not subscribed
		logger.error("Not subscribed to topic " + subscriptionTopic);
		return new ResponseEntity<>("{'description': 'Was not subscribed'}", HttpStatus.BAD_REQUEST);
	}

	try {
		DefaultMessageListenerContainer listenercontainer = this.listenerContainersMap.get(subscriptionTopic);
		listenercontainer.stop();
        listenercontainer.destroy();
        this.listenerContainersMap.remove(subscriptionTopic);

	} catch (Exception e) {
		logger.error("Service Creation failed.", e);
		return new ResponseEntity<>("{'description': '" + e.getMessage() + "'}", HttpStatus.BAD_REQUEST);
	}
	logger.info("Finished Deleting a subscription to topic: " + subscriptionTopic);
	return new ResponseEntity<>("{}", HttpStatus.OK);
}
 
Example #22
Source Project: solace-samples-cloudfoundry-java   Author: SolaceSamples   File: SolaceController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/subscription", method = RequestMethod.POST)
public ResponseEntity<String> addSubscription(@RequestBody SimpleSubscription subscription) {
	String subscriptionTopic = subscription.getSubscription();

	logger.info("Adding a subscription to topic: " + subscriptionTopic);

	if ( this.listenerContainersMap.containsKey(subscriptionTopic) ) {
		// Already subscribed
		logger.error("Already subscribed to topic " + subscriptionTopic);
		return new ResponseEntity<>("{'description': 'Already subscribed'}", HttpStatus.BAD_REQUEST);
	}

	// Then create a listener
	try {
    	DefaultMessageListenerContainer listenercontainer = createListener(subscriptionTopic);
        listenercontainer.start();
        this.listenerContainersMap.put(subscriptionTopic, listenercontainer);
	} catch (Exception e) {
		logger.error("Service Creation failed.", e);
		return new ResponseEntity<>("{'description': '" + e.getMessage() + "'}", HttpStatus.BAD_REQUEST);
	}
	logger.info("Finished Adding a subscription to topic: " + subscriptionTopic);
	return new ResponseEntity<>("{}", HttpStatus.OK);
}
 
Example #23
Source Project: spring-analysis-note   Author: Vip-Augus   File: DefaultJmsListenerContainerFactory.java    License: MIT License 5 votes vote down vote up
@Override
protected void initializeContainer(DefaultMessageListenerContainer container) {
	if (this.taskExecutor != null) {
		container.setTaskExecutor(this.taskExecutor);
	}
	if (this.transactionManager != null) {
		container.setTransactionManager(this.transactionManager);
	}

	if (this.cacheLevel != null) {
		container.setCacheLevel(this.cacheLevel);
	}
	else if (this.cacheLevelName != null) {
		container.setCacheLevelName(this.cacheLevelName);
	}

	if (this.concurrency != null) {
		container.setConcurrency(this.concurrency);
	}
	if (this.maxMessagesPerTask != null) {
		container.setMaxMessagesPerTask(this.maxMessagesPerTask);
	}
	if (this.receiveTimeout != null) {
		container.setReceiveTimeout(this.receiveTimeout);
	}

	if (this.backOff != null) {
		container.setBackOff(this.backOff);
		if (this.recoveryInterval != null) {
			logger.info("Ignoring recovery interval in DefaultJmsListenerContainerFactory in favor of BackOff");
		}
	}
	else if (this.recoveryInterval != null) {
		container.setRecoveryInterval(this.recoveryInterval);
	}
}
 
Example #24
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testBeansCreated() {
	Map<String, ?> containers = context.getBeansOfType(DefaultMessageListenerContainer.class);
	assertEquals("Context should contain 3 JMS listener containers", 3, containers.size());

	containers = context.getBeansOfType(GenericMessageEndpointManager.class);
	assertEquals("Context should contain 3 JCA endpoint containers", 3, containers.size());

	Map<String, JmsListenerContainerFactory> containerFactories =
			context.getBeansOfType(JmsListenerContainerFactory.class);
	assertEquals("Context should contain 3 JmsListenerContainerFactory instances", 3, containerFactories.size());
}
 
Example #25
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testListeners() throws Exception {
	TestBean testBean1 = context.getBean("testBean1", TestBean.class);
	TestBean testBean2 = context.getBean("testBean2", TestBean.class);
	TestMessageListener testBean3 = context.getBean("testBean3", TestMessageListener.class);

	assertNull(testBean1.getName());
	assertNull(testBean2.getName());
	assertNull(testBean3.message);

	TextMessage message1 = mock(TextMessage.class);
	given(message1.getText()).willReturn("Test1");

	MessageListener listener1 = getListener("listener1");
	listener1.onMessage(message1);
	assertEquals("Test1", testBean1.getName());

	TextMessage message2 = mock(TextMessage.class);
	given(message2.getText()).willReturn("Test2");

	MessageListener listener2 = getListener("listener2");
	listener2.onMessage(message2);
	assertEquals("Test2", testBean2.getName());

	TextMessage message3 = mock(TextMessage.class);

	MessageListener listener3 = getListener(DefaultMessageListenerContainer.class.getName() + "#0");
	listener3.onMessage(message3);
	assertSame(message3, testBean3.message);
}
 
Example #26
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testRecoveryInterval() {
	Object testBackOff = context.getBean("testBackOff");
	BackOff backOff1 = getBackOff("listener1");
	BackOff backOff2 = getBackOff("listener2");
	long recoveryInterval3 = getRecoveryInterval(DefaultMessageListenerContainer.class.getName() + "#0");

	assertSame(testBackOff, backOff1);
	assertSame(testBackOff, backOff2);
	assertEquals(DefaultMessageListenerContainer.DEFAULT_RECOVERY_INTERVAL, recoveryInterval3);
}
 
Example #27
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testConcurrency() {
	// JMS
	DefaultMessageListenerContainer listener0 = this.context
			.getBean(DefaultMessageListenerContainer.class.getName() + "#0", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);

	assertEquals("Wrong concurrency on listener using placeholder", 2, listener0.getConcurrentConsumers());
	assertEquals("Wrong concurrency on listener using placeholder", 3, listener0.getMaxConcurrentConsumers());
	assertEquals("Wrong concurrency on listener1", 3, listener1.getConcurrentConsumers());
	assertEquals("Wrong max concurrency on listener1", 5, listener1.getMaxConcurrentConsumers());
	assertEquals("Wrong custom concurrency on listener2", 5, listener2.getConcurrentConsumers());
	assertEquals("Wrong custom max concurrency on listener2", 10, listener2.getMaxConcurrentConsumers());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong concurrency on listener3", 5,
			listener3.getActivationSpecConfig().getMaxConcurrency());
	assertEquals("Wrong custom concurrency on listener4", 7,
			listener4.getActivationSpecConfig().getMaxConcurrency());
}
 
Example #28
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testErrorHandlers() {
	ErrorHandler expected = this.context.getBean("testErrorHandler", ErrorHandler.class);
	ErrorHandler errorHandler1 = getErrorHandler("listener1");
	ErrorHandler errorHandler2 = getErrorHandler("listener2");
	ErrorHandler defaultErrorHandler = getErrorHandler(DefaultMessageListenerContainer.class.getName() + "#0");
	assertSame(expected, errorHandler1);
	assertSame(expected, errorHandler2);
	assertNull(defaultErrorHandler);
}
 
Example #29
Source Project: spring-analysis-note   Author: Vip-Augus   File: JmsNamespaceHandlerTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testPhases() {
	int phase1 = getPhase("listener1");
	int phase2 = getPhase("listener2");
	int phase3 = getPhase("listener3");
	int phase4 = getPhase("listener4");
	int defaultPhase = getPhase(DefaultMessageListenerContainer.class.getName() + "#0");
	assertEquals(99, phase1);
	assertEquals(99, phase2);
	assertEquals(77, phase3);
	assertEquals(77, phase4);
	assertEquals(Integer.MAX_VALUE, defaultPhase);
}
 
Example #30
Source Project: c2mon   Author: c2mon   File: JmsConfig.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public DefaultMessageListenerContainer secondServerRequestListenerContainer() {
  DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
  container.setConnectionFactory(secondSingleConnectionFactory());
  container.setDestinationName("replaced-at-runtime");
  container.setSessionTransacted(false);
  container.setMaxMessagesPerTask(1);
  container.setReceiveTimeout(1000);
  container.setIdleTaskExecutionLimit(10);
  container.setAutoStartup(false);
  return container;
}