Java Code Examples for org.springframework.jms.listener.DefaultMessageListenerContainer#setMaxMessagesPerTask()

The following examples show how to use org.springframework.jms.listener.DefaultMessageListenerContainer#setMaxMessagesPerTask() . 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: 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 3
Source File: JmsContainerManagerImpl.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the container so that it can be started manually when added during
 * server runtime.
 * @param process the Process to create a container for
 * @param consumersMax the max number of consumers (at start-up subscribe with less)
 * @return the JMS container that was created
 */
private DefaultMessageListenerContainer subscribe(final Process process, final int consumersMax) {
  DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
  container.setConnectionFactory(updateConnectionFactory);
  container.setDestination(new ActiveMQQueue(properties.getJms().getQueuePrefix() + ".update." + process.getName()));
  container.setMessageListener(listener);
  container.setConcurrentConsumers(properties.getJms().getUpdate().getInitialConsumers());
  container.setMaxConcurrentConsumers(consumersMax);
  container.setSessionTransacted(properties.getJms().getUpdate().isTransacted());
  container.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
  container.setAutoStartup(false);
  container.setPhase(ServerConstants.PHASE_START_LAST);
  container.setMaxMessagesPerTask(properties.getJms().getUpdate().getMaxMessagesPerTask());
  container.setReceiveTimeout(properties.getJms().getUpdate().getReceiveTimeout());
  container.setIdleTaskExecutionLimit(properties.getJms().getUpdate().getIdleTaskExecutionLimit());
  container.setBeanName(process.getName() + " update JMS container");
  container.setTaskExecutor(daqThreadPoolTaskExecutor);
  container.setAcceptMessagesWhileStopping(false);
  jmsContainers.put(process.getId(), container);
  container.initialize();
  return container;
}
 
Example 4
Source File: DefaultJmsListenerContainerFactory.java    From spring-analysis-note with 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 5
Source File: DefaultJmsListenerContainerFactory.java    From java-technology-stack with 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 6
Source File: DefaultJmsListenerContainerFactory.java    From spring4-understanding with Apache License 2.0 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.warn("Ignoring recovery interval in DefaultJmsListenerContainerFactory in favor of BackOff");
		}
	}
	else if (this.recoveryInterval != null) {
		container.setRecoveryInterval(this.recoveryInterval);
	}
}
 
Example 7
Source File: JmsConfig.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public DefaultMessageListenerContainer serverRequestListenerContainer() {
  DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
  container.setConnectionFactory(singleConnectionFactory());
  container.setDestinationName("replaced-at-runtime");
  container.setSessionTransacted(false);
  container.setMaxMessagesPerTask(1);
  container.setReceiveTimeout(1000);
  container.setIdleTaskExecutionLimit(10);
  container.setAutoStartup(false);
  return container;
}
 
Example 8
Source File: JmsConfig.java    From c2mon with 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;
}