Search in sources :

Example 1 with DefaultJmsMessageListenerContainer

use of org.apache.camel.component.jms.DefaultJmsMessageListenerContainer in project camel by apache.

the class TemporaryQueueReplyManager method createListenerContainer.

@Override
protected AbstractMessageListenerContainer createListenerContainer() throws Exception {
    // Use DefaultMessageListenerContainer as it supports reconnects (see CAMEL-3193)
    DefaultMessageListenerContainer answer = new DefaultJmsMessageListenerContainer(endpoint, endpoint.isAllowReplyManagerQuickStop());
    answer.setDestinationName("temporary");
    answer.setDestinationResolver(destResolver);
    answer.setAutoStartup(true);
    if (endpoint.getMaxMessagesPerTask() >= 0) {
        answer.setMaxMessagesPerTask(endpoint.getMaxMessagesPerTask());
    }
    answer.setIdleConsumerLimit(endpoint.getIdleConsumerLimit());
    answer.setIdleTaskExecutionLimit(endpoint.getIdleTaskExecutionLimit());
    answer.setMessageListener(this);
    answer.setPubSubDomain(false);
    answer.setSubscriptionDurable(false);
    answer.setConcurrentConsumers(endpoint.getReplyToConcurrentConsumers());
    if (endpoint.getReplyToMaxConcurrentConsumers() > 0) {
        answer.setMaxConcurrentConsumers(endpoint.getReplyToMaxConcurrentConsumers());
    }
    answer.setConnectionFactory(endpoint.getConnectionFactory());
    // msgs from the JMS Connection that created the temp destination in the first place
    if (endpoint.getReplyToCacheLevelName() != null) {
        if ("CACHE_NONE".equals(endpoint.getReplyToCacheLevelName())) {
            throw new IllegalArgumentException("ReplyToCacheLevelName cannot be CACHE_NONE when using temporary reply queues. The value must be either CACHE_CONSUMER, or CACHE_SESSION");
        }
        answer.setCacheLevelName(endpoint.getReplyToCacheLevelName());
    } else {
        answer.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
    }
    String clientId = endpoint.getClientId();
    if (clientId != null) {
        clientId += ".CamelReplyManager";
        answer.setClientId(clientId);
    }
    // we cannot do request-reply over JMS with transaction
    answer.setSessionTransacted(false);
    // other optional properties
    answer.setExceptionListener(new TemporaryReplyQueueExceptionListener(destResolver, endpoint.getExceptionListener()));
    if (endpoint.getErrorHandler() != null) {
        answer.setErrorHandler(endpoint.getErrorHandler());
    } else {
        answer.setErrorHandler(new DefaultSpringErrorHandler(endpoint.getCamelContext(), TemporaryQueueReplyManager.class, endpoint.getErrorHandlerLoggingLevel(), endpoint.isErrorHandlerLogStackTrace()));
    }
    if (endpoint.getReceiveTimeout() >= 0) {
        answer.setReceiveTimeout(endpoint.getReceiveTimeout());
    }
    if (endpoint.getRecoveryInterval() >= 0) {
        answer.setRecoveryInterval(endpoint.getRecoveryInterval());
    }
    if (endpoint.getTaskExecutor() != null) {
        if (log.isDebugEnabled()) {
            log.debug("Using custom TaskExecutor: {} on listener container: {}", endpoint.getTaskExecutor(), answer);
        }
        answer.setTaskExecutor(endpoint.getTaskExecutor());
    }
    // setup a bean name which is used by Spring JMS as the thread name
    // use the name of the request destination
    String name = "TemporaryQueueReplyManager[" + endpoint.getDestinationName() + "]";
    answer.setBeanName(name);
    if (answer.getConcurrentConsumers() > 1) {
        // log that we are using concurrent consumers
        log.info("Using {}-{} concurrent consumers on {}", new Object[] { answer.getConcurrentConsumers(), answer.getMaxConcurrentConsumers(), name });
    }
    return answer;
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) DefaultJmsMessageListenerContainer(org.apache.camel.component.jms.DefaultJmsMessageListenerContainer) DefaultSpringErrorHandler(org.apache.camel.component.jms.DefaultSpringErrorHandler)

Aggregations

DefaultJmsMessageListenerContainer (org.apache.camel.component.jms.DefaultJmsMessageListenerContainer)1 DefaultSpringErrorHandler (org.apache.camel.component.jms.DefaultSpringErrorHandler)1 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)1