org.springframework.jms.listener.DefaultMessageListenerContainer Java Examples

The following examples show how to use org.springframework.jms.listener.DefaultMessageListenerContainer. 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: AdminJmsConfig.java    From c2mon with 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 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 #3
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with 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 #4
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with 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 #5
Source File: ClientJmsConfig.java    From c2mon with 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 #6
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with 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 #7
Source File: JmsSourceTests.java    From spring-cloud-stream-app-starters with 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 #8
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 #9
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with 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 #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: JmsContainerManagerImpl.java    From c2mon with 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 #12
Source File: Listener.java    From oneops with 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 #13
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with 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 #14
Source File: SolaceController.java    From solace-samples-cloudfoundry-java with 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 #15
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with 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 #16
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with 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 #17
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with 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 #18
Source File: SolaceController.java    From solace-samples-cloudfoundry-java with 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 #19
Source File: SolaceController.java    From solace-samples-cloudfoundry-java with 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 #20
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with 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 #21
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with 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 #22
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with 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 #23
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 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 #24
Source File: Listener.java    From oneops with Apache License 2.0 5 votes vote down vote up
/**
 * check for free space - shutdownshutdown listener and gracefully exit if full
 */
@SuppressWarnings("static-access")
private void checkFreeSpace() {
  long freeMB = dataDir.getFreeSpace() / 1024 / 1024;

  if (freeMB < config.getMinFreeSpaceMB()) {
    DefaultMessageListenerContainer listenerContainer = (DefaultMessageListenerContainer)
        applicationContext.getBean("listenerContainer");

    logger.info("Stopping listener container due to "
        + config.getDataDir() + " free space mb: "
        + freeMB + " ... min_free_space_mb: " + config.getMinFreeSpaceMB());

    listenerContainer.stop();
    while (activeThreads.get() > 0) {
      logger
          .error("Shutdown in progress due " + config.getDataDir() + " free space mb: "
              + freeMB + " ... min_free_space_mb: " + config.getMinFreeSpaceMB()
              + ". sleeping for 10sec. activeThreads: " + activeThreads);
      try {
        Thread.currentThread().sleep(10000);
      } catch (InterruptedException e) {
        logger.info(
            "Got InterruptedException, but will still let the activeThreads complete.");
      }
    }
    Runtime.getRuntime().exit(1);
  } else {
    logger.info(config.getDataDir() + " free space mb: " + freeMB);
  }
}
 
Example #25
Source File: AbstractConsumer.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
public void afterPropertiesSet() {
    if(this.consumerConfig.getBrokerUrlList() != null && !this.consumerConfig.getBrokerUrlList().isEmpty() && !Strings.isNullOrEmpty(this.consumerConfig.getQueueName())) {

        for(String brokerUrl : this.consumerConfig.getBrokerUrlList()) {
            //ConnectionFactory connectionFactory = ConnectionFactoryContainer.getSingleConsumerConnectionFactory(brokerUrl);
            ConnectionFactory connectionFactory = ConnectionFactoryContainer.getConsumerConnectionFactory(brokerUrl);
            if (this.listenerContainerMap.containsKey(connectionFactory)) {
                continue;
            }

            DefaultMessageListenerContainer defaultMessageListenerContainer = new DefaultMessageListenerContainer();

            defaultMessageListenerContainer.setCacheLevel(this.consumerConfig.getCacheLevel());
            defaultMessageListenerContainer.setConcurrentConsumers(this.consumerConfig.getConcurrentConsumers());
            ActiveMQQueue activeMQQueue = new ActiveMQQueue();
            activeMQQueue.setPhysicalName(this.consumerConfig.getQueueName());
            if(this.consumerConfig.getAcknowledgemode() < 0 || this.consumerConfig.getAcknowledgemode() > 4) {
                this.consumerConfig.setAcknowledgemode( Session.AUTO_ACKNOWLEDGE);
            }

            if(this.consumerConfig.getAcknowledgemode() == Session.SESSION_TRANSACTED) {
                defaultMessageListenerContainer.setSessionTransacted(true);
            }

            defaultMessageListenerContainer.setSessionAcknowledgeMode(this.consumerConfig.getAcknowledgemode());

            defaultMessageListenerContainer.setConnectionFactory(connectionFactory);
            defaultMessageListenerContainer.setDestination(activeMQQueue);
            defaultMessageListenerContainer.setMessageListener(this);
            defaultMessageListenerContainer.initialize();
            defaultMessageListenerContainer.start();
            this.listenerContainerMap.put(connectionFactory, defaultMessageListenerContainer);

        }
    }
}
 
Example #26
Source File: JmsProducerConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public DefaultMessageListenerContainer containerListener() {
    final DefaultMessageListenerContainer listener = new DefaultMessageListenerContainer();
    listener.setConnectionFactory(jmsCommonConfig.connectionFactory());
    listener.setDestination(jmsCommonConfig.confirmationQueue());
    listener.setMessageListener(confirmationReceiver());
    return listener;
}
 
Example #27
Source File: MQAutoConfiguration.java    From elephant with Apache License 2.0 5 votes vote down vote up
private void start(String beanName){
	if(StringUtils.isEmpty(beanName)){
		return;
	}
	DefaultMessageListenerContainer c = this.applicationContext.
			getBean(beanName,DefaultMessageListenerContainer.class);
	if(c != null)c.start();
}
 
Example #28
Source File: MQAutoConfiguration.java    From elephant with Apache License 2.0 5 votes vote down vote up
private void registerListener(String registerBeanName,Destination destination,Object bean,Method method,int retryTimes,boolean isRetry){
	DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)this.applicationContext.getAutowireCapableBeanFactory();  
         
       BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultMessageListenerContainer.class);  
       beanDefinitionBuilder.addPropertyValue("connectionFactory",this.connectionFactory);  
       beanDefinitionBuilder.addPropertyValue("destination", destination);  
       beanDefinitionBuilder.addPropertyValue("messageListener",new SessionAwareMessageListenerImpl(bean, method,retryTimes,isRetry,this.jmsTemplate));
       beanDefinitionBuilder.addPropertyValue("sessionAcknowledgeMode",4);
       
       beanFactory.registerBeanDefinition(registerBeanName, beanDefinitionBuilder.getBeanDefinition());
}
 
Example #29
Source File: AntennaListenerTest.java    From oneops with Apache License 2.0 5 votes vote down vote up
/**
 * Set up the instance
 */
@BeforeClass
public void config() {
    System.setProperty("oneops.url", "http://oneops.com");
    MockitoAnnotations.initMocks(this);
    this.listener.setDmlc(mock(DefaultMessageListenerContainer.class));
    this.listener.init();
}
 
Example #30
Source File: ReceiverConfig.java    From spring-jms with MIT License 5 votes vote down vote up
@Bean
public DefaultMessageListenerContainer orderMessageListenerContainer() {
  SimpleJmsListenerEndpoint endpoint =
      new SimpleJmsListenerEndpoint();
  endpoint.setMessageListener(new StatusMessageListener("DMLC"));
  endpoint.setDestination(status1Destination);

  return orderDefaultJmsListenerContainerFactory()
      .createListenerContainer(endpoint);
}