Integratec API Platform
|
The following sections assume you've already successfully downloaded, installed, and configured the Integratec modules you're intending to use.
There are two ways to start Integratec modules:
Note: The Client API is not able to make requests until both the Master and a Worker module capable of processing the request are running.
At a high level, all service requests with the Integratec API consist of two elements:
Service Identifier
This allows the platform to uniquely identify a request and route it to the correct type of worker module.
Request Parameters
Arguments for a given request must be serialized as a JSON string, described in further detail below.
See the following definition from json.org:
Below is an example JSON object:
{"employees": [ {"firstName":"John", "lastName":"Doe"}, {"firstName":"Anna", "lastName":"Smith"}, {"firstName":"Peter", "lastName":"Jones"} ] }
All Integratec requests expect, at a bare minimum, an empty JSON object: {}
. The great majority of them require specific parameters inside that object in order for the worker to know how to process the request.
The most basic method is writing the string by hand:
C:
C#:
Java:
Python:
Depending on your language of choice, your mileage may vary with this method; at best it's useful for quick tests and samples. If you intend to really take programmatic advantage of the API, you'll want to use a library that provides an easy-to-use interface for serializing your data into JSON. The following is a list of suggested libraries for the languages we support:
The JSON specification RFC 4627 states that "The names within an object SHOULD be unique." For example, the following JSON is valid, but the names inside the object are not unique.
{ "exampleName": "value1", "exampleName": "value2" }
Integratec checks the request object for non-unique names. It also recursively checks object and array type properties for non-unique names. If it finds a non-unique name, it reports an error and does not send the request.
One of your greatest resources for understanding what to send and expect back from the Integratec platform is a series of schema files found in the /schemas
folder within each local installation. Each service we offer has an associated schema file for both the Request and the Reply: <ServiceID>-Req.json
and <ServiceID>-Rep.json
, respectively.
IMPORTANT: DO NOT MODIFY THE SCHEMA FILES. IT CAN CAUSE SERIOUS UNEXPECTED ERRORS.
We use JSON-Schema to describe and validate the Request parameters (as well as the Reply result). You can read an excellent tutorial on JSON-Schema here. See below:
Example Schema:
{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "id": { "type": "integer" } }, "required": ["id"] }
Example Matching JSON:
{"id": 42}
Once all necessary modules are started, you can begin making requests of the Integratec platform.
Requests made by the Client API are sent to the Master, which routes them to an appropriate worker thread. Work is assigned with load-balancing (only available worker threads accept requests) and fair queuing (worker threads take turns accepting requests, even if all are available).
Making requests is accomplished via the following exported functions:
The first step is opening a Client API connection to the Integratec platform:
(c)
(c#)
(java)
(py)
Note: An opClientConnection object is NOT thread-safe, meaning that while you are allowed to use the object in multiple threads, you must ensure that you are not calling its methods simultaneously in multiple threads.
Your version of "Hello, world." is using the service GetBrokerIdentity, which returns the internal identifier of the Master as a string. We use the sendRequest
function, which initially returns a unique identifier (e.g. "{7BF91CB7-AAF6-435E-AEA3-6E67DE910A8C}"). This 'guid' is useful for getting the reply, filtering status updates, and cleaning up when you're done.
(c)
(c#)
(java)
(py)
Note: There are no parameters for a GetBrokerIdentity service request, hence the empty requestJson
JSON object.
Now that you have the 'guid', you can ask for the reply. It is possible to generate a request with one client connection, and to get the reply with another, assuming you saved the unique identifier.
The reply from the thread doing the work is always a JSON object, and adheres to that service's reply schema, just as you were required to adhere to the service's request schema.
(c)
(c#)
(java)
(py)
Note: The timeout parameter is set to 100 milliseconds. If the timeout is reached, an exception is raised.
The value of the replyJson
variable should look something like this:
{ "identity": "Master-DABB9" }
When a request is generated, both the Master and client retain record of the request. Using the deleteRequest function deletes that record. Again, you supply the unique identifier for the request and all record of it is removed.
(c)
(c#)
(java)
(py)
We've also provided a convenient method for sending a request, receiving the reply, and deleting record of it all synchronously, tied to the same timeout. The 'guid' for this request is not available, as record of the request is always deleted upon exiting the call.
(c)
(c#)
(java)
(py)
The last step is closing the connection:
(c)
(c#)
(java)
(py)
You can track the status of a request by implementing a status callback function, or where supported, making use of an event handler (e.g. .NET). Worker threads publish status updates once at startup, multiple times to represent progress, and once again when work is completed. The following diagram illustrates the sequence of messages, omitting the always-present routing Master module:
There are two parameters to the callback function, RequestID and Status:
RequestID
This is the unique identifier you received from generating the request.
Status
The status string is serialized as JSON, and always contains type
and TaskRunID
elements. See the following examples for the three possible types:
{ "statusType": "Started", "TaskRunID": 1, "MinionID": "Minion-AJ82JA4" }
type
describes the status update, allowing you to parse the other elements.TaskRunID
defaults to 1, and corresponds to a record in the persist table.MinionID
indicates which worker thread was assigned the request.{ "statusType": "Progress", "TaskRunID": 1, "currentPosition": 42, "maximumPosition": 9000, "message": "Doing all the things!" }
currentPosition
and maximumPosition
are the real-time progress of the request. A null value is considered indeterminate.message
is a caption-like string that describes the work currently in-progress{ "statusType": "Finished", "TaskRunID": 1 }
Note: Status updates do not wait in a queue for you get them. If you're not around to receive them, they are lost forever. Because of this, it is unwise to rely on them. In contrast, the reply for each RequestID will be waiting for you via receiveReply
regardless of which Client API connection you're on, or whether or not you had to reconnect, until you delete it with deleteRequest
.
Using status updates requires implementing a callback function. For example:
(c)
(c#)
(java)
(py)