Skip to content

Commit 393072f

Browse files
author
Vlad Ionescu
committed
additional client properties can now be specified via ConnectionFactory.setClientProperties(...)
1 parent afb5dc9 commit 393072f

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public class ConnectionFactory implements Cloneable {
7373
/** Default value for desired heartbeat interval; zero for none */
7474
public static final int DEFAULT_HEARTBEAT = 0;
7575

76+
/** Default extra client properties to be sent to the server */
77+
public static final Map<String, Object> DEFAULT_CLIENT_PROPERTIES =
78+
new HashMap<String, Object>();
79+
7680
/** The default host to connect to */
7781
public static final String DEFAULT_HOST = "localhost";
7882

@@ -90,15 +94,16 @@ public class ConnectionFactory implements Cloneable {
9094
*/
9195
public static final String DEFAULT_SSL_PROTOCOL = "SSLv3";
9296

93-
private String username = DEFAULT_USER;
94-
private String password = DEFAULT_PASS;
95-
private String virtualHost = DEFAULT_VHOST;
96-
private String host = DEFAULT_HOST;
97-
private int port = USE_DEFAULT_PORT;
98-
private int requestedChannelMax = DEFAULT_CHANNEL_MAX;
99-
private int requestedFrameMax = DEFAULT_FRAME_MAX;
100-
private int requestedHeartbeat = DEFAULT_HEARTBEAT;
101-
private SocketFactory factory = SocketFactory.getDefault();
97+
private String username = DEFAULT_USER;
98+
private String password = DEFAULT_PASS;
99+
private String virtualHost = DEFAULT_VHOST;
100+
private String host = DEFAULT_HOST;
101+
private int port = USE_DEFAULT_PORT;
102+
private int requestedChannelMax = DEFAULT_CHANNEL_MAX;
103+
private int requestedFrameMax = DEFAULT_FRAME_MAX;
104+
private int requestedHeartbeat = DEFAULT_HEARTBEAT;
105+
private Map<String, Object> _clientProperties = DEFAULT_CLIENT_PROPERTIES;
106+
private SocketFactory factory = SocketFactory.getDefault();
102107

103108
/**
104109
* Instantiate a ConnectionFactory with a default set of parameters.
@@ -236,6 +241,22 @@ public void setRequestedHeartbeat(int requestedHeartbeat) {
236241
this.requestedHeartbeat = requestedHeartbeat;
237242
}
238243

244+
/**
245+
* Retrieve the map of extra client properties to be sent to the server
246+
* @return the map of extra client properties
247+
*/
248+
public Map<String, Object> getClientProperties() {
249+
return _clientProperties;
250+
}
251+
252+
/**
253+
* Set the extra client properties to be sent to the server
254+
* @param clientProperties the map of extra client properties
255+
*/
256+
public void setClientProperties(Map<String, Object> clientProperties) {
257+
_clientProperties = clientProperties;
258+
}
259+
239260
/**
240261
* Retrieve the socket factory used to make connections with.
241262
*/

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,19 @@ public class AMQConnection extends ShutdownNotifierComponent implements Connecti
7272
/** Timeout used while waiting for a connection.close-ok (milliseconds) */
7373
public static final int CONNECTION_CLOSING_TIMEOUT = 10000;
7474

75-
private static final Object[] DEFAULT_CLIENT_PROPERTIES = new Object[] {
76-
"product", LongStringHelper.asLongString("RabbitMQ"),
77-
"version", LongStringHelper.asLongString(ClientVersion.VERSION),
78-
"platform", LongStringHelper.asLongString("Java"),
79-
"copyright", LongStringHelper.asLongString(
80-
"Copyright (C) 2007-2008 LShift Ltd., " +
81-
"Cohesive Financial Technologies LLC., " +
82-
"and Rabbit Technologies Ltd."),
83-
"information", LongStringHelper.asLongString(
84-
"Licensed under the MPL. " +
85-
"See http://www.rabbitmq.com/")
86-
};
75+
private static final Object[] DEFAULT_CLIENT_PROPERTIES_ARRAY =
76+
new Object[] {
77+
"product", LongStringHelper.asLongString("RabbitMQ"),
78+
"version", LongStringHelper.asLongString(ClientVersion.VERSION),
79+
"platform", LongStringHelper.asLongString("Java"),
80+
"copyright", LongStringHelper.asLongString(
81+
"Copyright (C) 2007-2008 LShift Ltd., " +
82+
"Cohesive Financial Technologies LLC., " +
83+
"and Rabbit Technologies Ltd."),
84+
"information", LongStringHelper.asLongString(
85+
"Licensed under the MPL. " +
86+
"See http://www.rabbitmq.com/")
87+
};
8788

8889
private static final Version clientVersion =
8990
new Version(AMQP.PROTOCOL.MAJOR, AMQP.PROTOCOL.MINOR);
@@ -159,6 +160,7 @@ public void ensureIsOpen()
159160

160161
private final String _username, _password, _virtualHost;
161162
private final int _requestedChannelMax, _requestedFrameMax, _requestedHeartbeat;
163+
private final Map<String, Object> _clientProperties;
162164

163165
/** {@inheritDoc} */
164166
public String getHost() {
@@ -207,6 +209,8 @@ public AMQConnection(ConnectionFactory factory,
207209
_requestedChannelMax = factory.getRequestedChannelMax();
208210
_requestedFrameMax = factory.getRequestedFrameMax();
209211
_requestedHeartbeat = factory.getRequestedHeartbeat();
212+
_clientProperties =
213+
buildClientPropertiesTable(factory.getClientProperties());
210214

211215
this.factory = factory;
212216
_frameHandler = frameHandler;
@@ -274,10 +278,8 @@ public void start(boolean insist)
274278
LongString saslResponse = LongStringHelper.asLongString("\0" + _username +
275279
"\0" + _password);
276280
AMQImpl.Connection.StartOk startOk =
277-
new AMQImpl.Connection.StartOk(buildClientPropertiesTable(),
278-
"PLAIN",
279-
saslResponse,
280-
"en_US");
281+
new AMQImpl.Connection.StartOk(_clientProperties, "PLAIN",
282+
saslResponse, "en_US");
281283

282284
AMQP.Connection.Tune connTune =
283285
(AMQP.Connection.Tune) _channel0.exnWrappingRpc(startOk).getMethod();
@@ -397,9 +399,11 @@ public void writeFrame(Frame f) throws IOException {
397399
_lastActivityTime = System.nanoTime();
398400
}
399401

400-
public Map<String, Object> buildClientPropertiesTable() {
401-
Map<String, Object> props = Frame.buildTable(DEFAULT_CLIENT_PROPERTIES);
402-
props.putAll(_params.getClientProperties());
402+
private static Map<String, Object> buildClientPropertiesTable(
403+
Map<String, Object> extraClientProperties) {
404+
Map<String, Object> props =
405+
Frame.buildTable(DEFAULT_CLIENT_PROPERTIES_ARRAY);
406+
props.putAll(extraClientProperties);
403407
return props;
404408
}
405409

0 commit comments

Comments
 (0)