allow configuring the clientID via the ConnectionFactory using brokerURI or JNDI properties
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/c15320bc Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/c15320bc Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/c15320bc Branch: refs/heads/master Commit: c15320bca153accc733cdbaf4b45e36a9217240e Parents: 617df63 Author: Robert Gemmell <rob...@apache.org> Authored: Wed Jan 14 15:05:30 2015 +0000 Committer: Robert Gemmell <rob...@apache.org> Committed: Wed Jan 14 15:05:30 2015 +0000 ---------------------------------------------------------------------- .../apache/qpid/jms/JmsConnectionFactory.java | 35 +++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/c15320bc/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java index 6a7dcf8..1ec9213 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java @@ -49,11 +49,13 @@ import org.slf4j.LoggerFactory; public class JmsConnectionFactory extends JNDIStorable implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory { private static final Logger LOG = LoggerFactory.getLogger(JmsConnectionFactory.class); + private static final String CLIENT_ID_PROP = "clientID"; private URI brokerURI; private URI localURI; private String username; private String password; + private String clientID; private boolean forceAsyncSend; private boolean alwaysSyncSend; private boolean sendAcksAsync; @@ -232,11 +234,25 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact protected <T extends JmsConnection> T configureConnection(T connection, String username, String password) throws JMSException { try { - PropertyUtil.setProperties(connection, PropertyUtil.getProperties(this)); + + Map<String, String> properties = PropertyUtil.getProperties(this); + // We must ensure that we apply the clientID last, since setting it on + // the Connection object provokes establishing the underlying connection. + boolean setClientID = false; + if(properties.containsKey(CLIENT_ID_PROP)) { + setClientID = true; + properties.remove(CLIENT_ID_PROP); + } + + PropertyUtil.setProperties(connection, properties); connection.setExceptionListener(exceptionListener); connection.setUsername(username); connection.setPassword(password); connection.setBrokerURI(brokerURI); + if(setClientID){ + connection.setClientID(clientID); + } + return connection; } catch (Exception e) { throw JmsExceptionSupport.create(e); @@ -542,6 +558,23 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact this.clientIdGenerator = clientIdGenerator; } + public String getClientID() { + return clientID; + } + + /** + * Sets the JMS clientID to use for connections created by this factory. + * + * NOTE: A clientID can only be used by one Connection at a time, so setting it here + * will restrict the ConnectionFactory to creating a single open Connection at a time. + * It is possible to set the clientID on the Connection itself immediately after + * creation if no value has been set via the factory that created it, which will + * allow the factory to create multiple open connections at a time. + */ + public void setClientID(String clientID) { + this.clientID = clientID; + } + /** * Sets the prefix used by connection id generator. * --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org