Skip to content

Commit c362df1

Browse files
author
Vlad Ionescu
committed
additional client properties may now be specified via ConnectionParameters
1 parent 7b33b08 commit c362df1

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/com/rabbitmq/client/ConnectionParameters.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
package com.rabbitmq.client;
3232

3333
import java.security.AccessControlException;
34+
import java.util.Map;
35+
import java.util.HashMap;
3436

3537
/**
3638
* Properties bean to encapsulate parameters for a Connection.
@@ -65,12 +67,17 @@ private static String safeGetProperty(String key, String def) {
6567
/** Default value for desired heartbeat interval; zero for none */
6668
public static final int DEFAULT_HEARTBEAT = 0;
6769

70+
/** Default extra client properties to be sent to the server */
71+
public static final Map<String, Object> DEFAULT_CLIENT_PROPERTIES =
72+
new HashMap<String, Object>();
73+
6874
private String _userName = DEFAULT_USER;
6975
private String _password = DEFAULT_PASS;
7076
private String _virtualHost = DEFAULT_VHOST;
7177
private int _requestedChannelMax = DEFAULT_CHANNEL_MAX;
7278
private int _requestedFrameMax = DEFAULT_FRAME_MAX;
7379
private int _requestedHeartbeat = DEFAULT_HEARTBEAT;
80+
private Map<String, Object> _clientProperties = DEFAULT_CLIENT_PROPERTIES;
7481

7582
/**
7683
* Instantiate a set of parameters with all values set to the defaults
@@ -173,4 +180,19 @@ public void setRequestedChannelMax(int requestedChannelMax) {
173180
_requestedChannelMax = requestedChannelMax;
174181
}
175182

183+
/**
184+
* Retrieve the map of extra client properties to be sent to the server
185+
* @return the map of extra client properties
186+
*/
187+
public Map<String, Object> getClientProperties() {
188+
return _clientProperties;
189+
}
190+
191+
/**
192+
* Set the extra client properties to be sent to the server
193+
* @param clientProperties the map of extra client properties
194+
*/
195+
public void setClientProperties(Map<String, Object> clientProperties) {
196+
_clientProperties = clientProperties;
197+
}
176198
}

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

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

76+
private static final Object[] DEFAULT_CLIENT_PROPERTIES = 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+
};
88+
7689
private static final Version clientVersion =
7790
new Version(AMQP.PROTOCOL.MAJOR, AMQP.PROTOCOL.MINOR);
7891

@@ -376,16 +389,9 @@ public void writeFrame(Frame f) throws IOException {
376389
}
377390

378391
public Map<String, Object> buildClientPropertiesTable() {
379-
return Frame.buildTable(new Object[] {
380-
"product", LongStringHelper.asLongString("RabbitMQ"),
381-
"version", LongStringHelper.asLongString(ClientVersion.VERSION),
382-
"platform", LongStringHelper.asLongString("Java"),
383-
"copyright", LongStringHelper.asLongString("Copyright (C) 2007-2008 LShift Ltd., " +
384-
"Cohesive Financial Technologies LLC., " +
385-
"and Rabbit Technologies Ltd."),
386-
"information", LongStringHelper.asLongString("Licensed under the MPL. " +
387-
"See http://www.rabbitmq.com/")
388-
});
392+
Map<String, Object> props = Frame.buildTable(DEFAULT_CLIENT_PROPERTIES);
393+
props.putAll(_params.getClientProperties());
394+
return props;
389395
}
390396

391397
private static int negotiatedMaxValue(int clientValue, int serverValue) {

0 commit comments

Comments
 (0)