return destination;
}
};
protected AbstractMessageListenerContainer createListenerContainer() throws Exception {
DefaultMessageListenerContainer answer;
ReplyToType type = endpoint.getConfiguration().getReplyToType();
if (type == null) {
// use shared by default for persistent reply queues
type = ReplyToType.Shared;
}
if (ReplyToType.Shared == type) {
// shared reply to queues support either a fixed or dynamic JMS message selector
String replyToSelectorName = endpoint.getReplyToDestinationSelectorName();
if (replyToSelectorName != null) {
// create a random selector value we will use for the persistent reply queue
replyToSelectorValue = "ID:" + new BigInteger(24 * 8, new Random()).toString(16);
String fixedMessageSelector = replyToSelectorName + "='" + replyToSelectorValue + "'";
answer = new SharedPersistentQueueMessageListenerContainer(fixedMessageSelector);
log.debug("Using shared queue: " + endpoint.getReplyTo() + " with fixed message selector [" + fixedMessageSelector + "] as reply listener: " + answer);
} else {
// use a dynamic message selector which will select the message we want to receive as reply
dynamicMessageSelector = new MessageSelectorCreator(correlation);
answer = new SharedPersistentQueueMessageListenerContainer(dynamicMessageSelector);
log.debug("Using shared queue: " + endpoint.getReplyTo() + " with dynamic message selector as reply listener: " + answer);
}
} else if (ReplyToType.Exclusive == type) {
answer = new ExclusivePersistentQueueMessageListenerContainer();
log.debug("Using exclusive queue:" + endpoint.getReplyTo() + " as reply listener: " + answer);
} else {
throw new IllegalArgumentException("ReplyToType " + type + " is not supported for persistent reply queues");
}
DestinationResolver resolver = endpoint.getDestinationResolver();
if (resolver == null) {
resolver = answer.getDestinationResolver();
}
answer.setDestinationResolver(new DestinationResolverDelegate(resolver));
answer.setDestinationName(endpoint.getReplyTo());
answer.setAutoStartup(true);
answer.setMessageListener(this);
answer.setPubSubDomain(false);
answer.setSubscriptionDurable(false);
answer.setConcurrentConsumers(1);
answer.setMaxConcurrentConsumers(1);
answer.setConnectionFactory(endpoint.getConnectionFactory());
String clientId = endpoint.getClientId();
if (clientId != null) {
clientId += ".CamelReplyManager";
answer.setClientId(clientId);
}
// must use cache level session
answer.setCacheLevel(DefaultMessageListenerContainer.CACHE_SESSION);
// we cannot do request-reply over JMS with transaction
answer.setSessionTransacted(false);
// other optional properties
if (endpoint.getExceptionListener() != null) {
answer.setExceptionListener(endpoint.getExceptionListener());
}
if (endpoint.getErrorHandler() != null) {
answer.setErrorHandler(endpoint.getErrorHandler());
}
if (endpoint.getReceiveTimeout() >= 0) {
answer.setReceiveTimeout(endpoint.getReceiveTimeout());
}
if (endpoint.getRecoveryInterval() >= 0) {
answer.setRecoveryInterval(endpoint.getRecoveryInterval());
}
// do not use a task executor for reply as we are are always a single threaded task
// setup a bean name which is used ny Spring JMS as the thread name
String name = "PersistentQueueReplyManager[" + answer.getDestinationName() + "]";
name = endpoint.getCamelContext().getExecutorServiceStrategy().getThreadName(name);
answer.setBeanName(name);
return answer;
}