mirror of https://github.com/apache/activemq.git
Add property preferJndiDestinationLookup so that users can override the default order as needed and have the connector first go to JNDI before trying the JMS create method. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1388326 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
de7617e9c7
commit
c176fa8f33
|
@ -50,6 +50,7 @@ public abstract class JmsConnector implements Service {
|
|||
private static int nextId;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JmsConnector.class);
|
||||
|
||||
protected boolean preferJndiDestinationLookup = false;
|
||||
protected JndiTemplate jndiLocalTemplate;
|
||||
protected JndiTemplate jndiOutboundTemplate;
|
||||
protected JmsMesageConvertor inboundMessageConvertor;
|
||||
|
@ -374,6 +375,25 @@ public abstract class JmsConnector implements Service {
|
|||
this.policy = policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the preferJndiDestinationLookup
|
||||
*/
|
||||
public boolean isPreferJndiDestinationLookup() {
|
||||
return preferJndiDestinationLookup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the connector should prefer to first try to find a destination in JNDI before
|
||||
* using JMS semantics to create a Destination. By default the connector will first use JMS
|
||||
* semantics and then fall-back to JNDI lookup, setting this value to true will reverse that
|
||||
* ordering.
|
||||
*
|
||||
* @param preferJndiDestinationLookup the preferJndiDestinationLookup to set
|
||||
*/
|
||||
public void setPreferJndiDestinationLookup(boolean preferJndiDestinationLookup) {
|
||||
this.preferJndiDestinationLookup = preferJndiDestinationLookup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return returns true if the {@link JmsConnector} is connected to both brokers.
|
||||
*/
|
||||
|
|
|
@ -429,6 +429,23 @@ public class JmsQueueConnector extends JmsConnector {
|
|||
|
||||
protected Queue createForeignQueue(QueueSession session, String queueName) throws JMSException {
|
||||
Queue result = null;
|
||||
|
||||
if (preferJndiDestinationLookup) {
|
||||
try {
|
||||
// look-up the Queue
|
||||
result = (Queue)jndiOutboundTemplate.lookup(queueName, Queue.class);
|
||||
} catch (NamingException e) {
|
||||
try {
|
||||
result = session.createQueue(queueName);
|
||||
} catch (JMSException e1) {
|
||||
String errStr = "Failed to look-up or create Queue for name: " + queueName;
|
||||
LOG.error(errStr, e);
|
||||
JMSException jmsEx = new JMSException(errStr);
|
||||
jmsEx.setLinkedException(e1);
|
||||
throw jmsEx;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
result = session.createQueue(queueName);
|
||||
} catch (JMSException e) {
|
||||
|
@ -443,7 +460,8 @@ public class JmsQueueConnector extends JmsConnector {
|
|||
throw jmsEx;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ import javax.jms.Connection;
|
|||
import javax.jms.Destination;
|
||||
import javax.jms.ExceptionListener;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.Topic;
|
||||
import javax.jms.TopicConnection;
|
||||
import javax.jms.TopicConnectionFactory;
|
||||
import javax.jms.TopicSession;
|
||||
import javax.jms.Session;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -426,6 +426,23 @@ public class JmsTopicConnector extends JmsConnector {
|
|||
|
||||
protected Topic createForeignTopic(TopicSession session, String topicName) throws JMSException {
|
||||
Topic result = null;
|
||||
|
||||
if (preferJndiDestinationLookup) {
|
||||
try {
|
||||
// look-up the Queue
|
||||
result = (Topic)jndiOutboundTemplate.lookup(topicName, Topic.class);
|
||||
} catch (NamingException e) {
|
||||
try {
|
||||
result = session.createTopic(topicName);
|
||||
} catch (JMSException e1) {
|
||||
String errStr = "Failed to look-up or create Topic for name: " + topicName;
|
||||
LOG.error(errStr, e);
|
||||
JMSException jmsEx = new JMSException(errStr);
|
||||
jmsEx.setLinkedException(e1);
|
||||
throw jmsEx;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
result = session.createTopic(topicName);
|
||||
} catch (JMSException e) {
|
||||
|
@ -440,6 +457,7 @@ public class JmsTopicConnector extends JmsConnector {
|
|||
throw jmsEx;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue