Sun GlassFish Message Queue 4.4 Developer's Guide for Java Clients

Overriding Configuration Settings

It is recommended that you use a connection factory just as you receive it from a JNDI lookup, with the property settings originally configured by your Message Queue administrator. However, there may be times when you need to override the preconfigured properties with different values of your own. You can do this from within your application code by calling the connection factory’s setProperty method. This method (inherited from the superclass AdministeredObject) takes two string arguments giving the name and value of the property to be set. The property names for the first argument are defined as static constants in the Message Queue class ConnectionConfiguration: for instance, the statement

myFactory.setProperty(ConnectionConfiguration.imqDefaultPassword,
                      "mellon");

sets the default password for establishing broker connections. See Connection Factory Attributes in Sun GlassFish Message Queue 4.4 Administration Guidefor complete information on the available connection factory configuration attributes.

It is also possible to override connection factory properties from the command line, by using the -D option to set their values when starting your client application. For example, the command line

java -DimqDefaultPassword=mellon MyMQClient

starts an application named MyMQClient with the same default password as in the preceding example. Setting a property value this way overrides any other value specified for it, whether preconfigured in the JNDI object store or set programmatically with the setProperty method.


Note –

A Message Queue administrator can prevent a connection factory’s properties from being overridden by specifying that the object be read-only when placing it in the object store. The properties of such a factory cannot be changed in any way, whether with the -D option from the command line or using the setProperty method from within your client application’s code. Any attempt to override the factory’s property values will simply be ignored.