Configuration Service

The Configuration Service allows you to configure remote services from a Kanzi Connect Server. After connecting to a Kanzi Connect Server, a remote service receives its configuration through the Configuration Service runtime data. This allows you to configure the services in a more flexible way, rather than hard-coding the values in your application code.

../_images/configuration-service.png

The configurations are stored in the Kanzi Connect Server configuration.xml file within the <published_configurations> element. After initialization the Configuration Service reads these elements and their values and publishes them in its runtime data. Configuration Service does not take any stand in what the data is, it just publishes the data that another service can read.

Below is an example of a configuration in a Kanzi Connect Server configuration.xml file that the Configuration Service publishes. This configuration defines four different types of configuration values within the my_example_service_config configuration group.

...
<published_configurations>
    <my_example_service_config>
      <attribute name="myStringItem"  type="string" value="str_value" />
      <attribute name="myIntegerItem" type="int"    value="14" />
      <attribute name="myFloatItem"   type="float"  value="1.5" />
      <attribute name="myBooleanItem" type="bool"   value="true" />
    </my_example_service_config>
</published_configurations>
...

The Configuration Service converts the above configuration to this Configuration Service runtime data. When a Kanzi Connect Server with this Configuration Service is running, you can access the configuration at http://localhost:8080/serviceruntimedata/Configuration.

data: {
   my_example_service_config: {
      myStringItem: "str_value",
      myIntegerItem: "14",
      myFloatItem: "1.500000",
      myBooleanItem: "1"
   }
}

When you define a configuration set for different services, place configuration for each service in its own configuration group. This makes the data easier to read and can provide performance benefits, because services can only subscribe to their own configurations and do not receive updates from other service configuration updates.

Using Configuration Service in java services

The provided java bindings contain a utility class RemoteConfigurationListener. You can use this class to get notifications about configuration changes in your java service. Its constructor takes the configuration group name and a callback interface which is invoked every time the configuration is received from a Kanzi Connect Server.

This code snippet shows how you can listen to the changes from the example configuration created above, and read one runtime data value.

public class MyService extends MyServiceConcept implements RemoteConfigurationListener.ConfigurationChangeCallback
{
   private RemoteConfigurationListener m_listener = new RemoteConfigurationListener(clientConnector, ”my_example_service_config”, this);
   ...
   public void onConfigurationChange(String uri, RuntimeDataObject data)
   {
       RuntimeDataObject_int myIntRuntimedataObject = RuntimeDataObjectUtil.getIntChild(parentObject, “myIntegerItem”);
       int myIntConfigurationValue = myIntRuntimedataObject.getValue();
    }
   ...
}

Interface definition

The interface definition XML file for the Configuration Service is stored in the

<KanziConnectInstallation>/SDK/sources/connect/core_services/configuration_service/interface/configuration_interface.xml

Fully qualified name for the Configuration Service is Connect.CoreService.Configuration.

Supported platforms

This service is supported on all platforms that Kanzi Connect supports.