Thursday, 20 September 2018

Access and Update Local Environment in Java

Access Local Environment in Java 


MbMessage localEnv = inAssembly.getLocalEnvironment();
MbElement nameVar = localEnv.getRootElement().getFirstElementByPath("Name");
String name = nameVar.getValueAsString();



Update Local Environment in Java 


MbMessage newEnv = new MbMessage(localEnv); newEnv.getRootElement().createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,"Name","James"); 
outAssembly = new MbMessageAssembly(inAssembly,newEnv,inAssembly.getExceptionList(),inAssembly.getMessage()); getOutputTerminal("out").propagate(outAssembly);

Wednesday, 19 September 2018

Accessing a Configurable Service using Java

The configurable service is a readily available to keep data that an integration message flow may need at runtime.

1.Create a User Defined Configurable Service using the web console and populate it.



2. The UserDefined Configurable Cervice properties can only be accessed using a JavaCompute node.

Import com.ibm.broker.config.proxy.* in your code.
  import com.ibm.broker.config.proxy.*; 

BrokerProxy b = BrokerProxy.getLocalInstance(); 
while(!b.hasBeenPopulatedByBroker())
{
   Thread.sleep(100); 
}
ConfigurableService vendorUDCS = b.getConfigurableService("UserDefined", "MyConfigService"); 
String vendorMQDetails  = vendorUDCS.getProperties().getProperty("server");


This method below will return an instance of the BrokerProxy object for the integration node to which the message flow is deployed.
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()) {
   Thread.sleep(100); 
}

The statement below will return a User Defined Configurable service called 'MyConfigService' ConfigurableService vendorUDCS = b.getConfigurableService("UserDefined", "MyConfigService");

You maybe interested in this post: Accessing a User Defined Configurable Service in Java