Configurable Services are typically runtime properties. We can use them to define properties that are related to external services on which the broker relies. Instead of defining properties on the node or message flow, we can create configurable services so that nodes and message flows can refer to them to find properties at run time. If we use this method, we can change the values of attributes for a configurable service on the broker, which then affects the behavior of a node or message flow without the need for redeployment.
This post shows how to use the CMP API in a JavaCompute node to query, set, create, and delete properties dynamically at run time in configurable services that we have defined with type UserDefined.
Java code :
Add the CMP JAR file install_dir/classes/ConfigManagerProxy.jar to the Java build path for the associated Java project.
Following imports are required for code :
- import com.ibm.broker.javacompute.MbJavaComputeNode;
- import com.ibm.broker.plugin.*;
- import com.ibm.broker.config.proxy.*;
Main Code
try{
BrokerProxy b = BrokerProxy.getLocalInstance();
//To ensure that the BrokerProxy object has been populated with data from the broker before we access the configurable service, Add the following code:
while(!b.hasBeenPopulatedByBroker()) {}
//As we have defined the configurable service with type 'UserDefined'; Add following code:
ConfigurableService[] CS_set = b.getConfigurableServices("UserDefined");
System.out.println("Configurable Service Name :"+CS_set[0].getName());
System.out.println("Property [Prop1] : "+CS_set[0].getProperties().getProperty("Prop1"));
CS_set[0].setProperty("Prop2" , "Setting property"); //To set a property
CS_set[0].deleteProperty("Prop2"); //To delete a property
}
catch (Exception e)
{
e.printStackTrace();
}
Output :
Configurable Service Name :UD1
Property [Prop1]: Prop1_Value
Setting Configurable Service in MQ explorer |
- mqsireportproperties ECSBRK -c UserDefined -o AllReportableEntityNames -r //To report Configurable Service of type 'UserDefined '.
- mqsicreateconfigurableservice ECSBRK -c UserDefined -o UD2 -n Prop3 -v Value3 //To create a Configurable Service.
- mqsideleteconfigurableservice ECSBRK -c UserDefined -o UD2 //To delete
- mqsichangeproperties ECSBRK -c UserDefined -o UD2 -n Prop4 -v Value4 // To add another property under same Configurable Service name UD2
- mqsichangeproperties ECSBRK -c UserDefined -o UD2 -n Prop3 -v Value33 // To change the existing property value.
Hi.. I am trying to chnage the value of userdefined configurable service using mqsichangeproperties command..but vlaue is not getting updated. my broker version is - 7003. Any idea about this?
ReplyDeleteyes i have an idea to your problem.
ReplyDeleteNote that the getLocalInstance() method will launch several Threads. Following your approach here will result in a large number of non-terminated Threads. You should either call disconnect() in a finally { } or store the BrokerProxy in a class-level field.
ReplyDelete