41
41
* but also from the classpath, by using the <code>classpath:</code> prefix
42
42
* in the location.
43
43
*
44
- * If default client properties should be set, set the <code>use.default.client.properties</code>
45
- * key to <code>true</code>. Custom client properties can be set by using
46
- * the <code>client.properties.</code>, e.g. <code>client.properties.app.name</code>.
44
+ * Client properties can be set by using
45
+ * the <code>client.properties.</code> prefix, e.g. <code>client.properties.app.name</code>.
46
+ * Default client properties and custom client properties are merged. To remove
47
+ * a default client property, set its key to an empty value.
47
48
*
48
49
* @since 4.4.0
49
50
* @see ConnectionFactory#load(String, String)
@@ -63,7 +64,6 @@ public class ConnectionFactoryConfigurator {
63
64
public static final String CONNECTION_TIMEOUT = "connection.timeout" ;
64
65
public static final String HANDSHAKE_TIMEOUT = "handshake.timeout" ;
65
66
public static final String SHUTDOWN_TIMEOUT = "shutdown.timeout" ;
66
- public static final String USE_DEFAULT_CLIENT_PROPERTIES = "use.default.client.properties" ;
67
67
public static final String CLIENT_PROPERTIES_PREFIX = "client.properties." ;
68
68
public static final String CONNECTION_RECOVERY_ENABLED = "connection.recovery.enabled" ;
69
69
public static final String TOPOLOGY_RECOVERY_ENABLED = "topology.recovery.enabled" ;
@@ -169,17 +169,21 @@ public static void load(ConnectionFactory cf, Map<String, String> properties, St
169
169
}
170
170
171
171
Map <String , Object > clientProperties = new HashMap <String , Object >();
172
- String useDefaultClientProperties = properties .get (prefix + USE_DEFAULT_CLIENT_PROPERTIES );
173
- if (useDefaultClientProperties != null && Boolean .valueOf (useDefaultClientProperties )) {
174
- clientProperties .putAll (AMQConnection .defaultClientProperties ());
175
- }
172
+ Map <String , Object > defaultClientProperties = AMQConnection .defaultClientProperties ();
173
+ clientProperties .putAll (defaultClientProperties );
176
174
177
175
for (Map .Entry <String , String > entry : properties .entrySet ()) {
178
176
if (entry .getKey ().startsWith (prefix + CLIENT_PROPERTIES_PREFIX )) {
179
- clientProperties .put (
180
- entry .getKey ().substring ((prefix + CLIENT_PROPERTIES_PREFIX ).length ()),
181
- entry .getValue ()
182
- );
177
+ String clientPropertyKey = entry .getKey ().substring ((prefix + CLIENT_PROPERTIES_PREFIX ).length ());
178
+ if (defaultClientProperties .containsKey (clientPropertyKey ) && (entry .getValue () == null || entry .getValue ().trim ().isEmpty ())) {
179
+ // if default property and value is empty, remove this property
180
+ clientProperties .remove (clientPropertyKey );
181
+ } else {
182
+ clientProperties .put (
183
+ clientPropertyKey ,
184
+ entry .getValue ()
185
+ );
186
+ }
183
187
}
184
188
}
185
189
cf .setClientProperties (clientProperties );
0 commit comments