Calling External Runtimes
It is often necessary to combine the results of multiple runtimes to produce the desired output. The preferred approach to do this is using the Network Runtime. If the Network Runtime functionality is not sufficient to acheive the desired results, it is possible to call one runtime from another using the callExternalRuntimeSync and callExternalRuntimeAsync methods.
How does it work?
To use the callExternalRuntimeSync method your post scoring logic must import com.ecosystem.plugin.lib.ExternalRuntimeSync. To use the callExternalRuntimeAsync method your post scoring logic must import com.ecosystem.plugin.lib.ExternalRuntimAsync. callExternalRuntimeSync and callExternalRuntimeAsync takes three arguments; params, overwrite_api, and url. params is the JSONObject object that is passed through the runtime process. overwrite_api is a JSONObject object that contains the parameters to be passed to the external runtime, this will override the values in params which are used as defaults. url is the endpoint of the external runtime to be called. This is illustrated in this truncated example:
String url = "http://ecosystem-runtime-two:8092";
JSONObject overwrite_api = new JSONObject();
overwrite_api.put("customer", customer_number);
overwrite_api.put("campaign", "demo-recommender");
overwrite_api.put("subcampaign", "demos");
overwrite_api.put("channel", "callExternal");
api_paroverwrite_apiams.put("result_count", 2);
overwrite_api.put("userid", "runtime_one");
overwrite_api.put("in_params", new JSONObject());
JSONObject response = ExternalRuntimeSync.callExternalRuntimeSync(params, overwrite_api, url);callExternalRuntimeSync will return the response from the runtime as a JSONObject object. The response can then be used in the remainder of the runtime process. Note that callExternalRuntimeAsync does not return the response from the external runtime, it merely triggers an asynchronous call to the configured runtime.