Asynchronous Replies
A common scenario is to push out some data into another system and receive some feedback from that operation at a later time. An example of such operation could be to invoke some kind of conversion service that converts files from one format to another. Such service typically operates in asynchronous mode.
Handling asynchronous replies from another system implies processing an executor twice.
Phase 1 - Sending the Data
During the first phase, the executor will typically collect some meta data and/or check-out some files, collect all of this and send to the remote service. After that, the executor will mark the job as "waiting for reply" via the "Execution Result" object.
This phase could be implemented like shown below:
// Perform work
// Mark the job as awaiting reply with some additional message.
context.result()
.awaitingReply(true)
.message('Data sent to system B.');
Phase 2 - Receiving the Reply
In the second phase, the reply processing takes place.
The remote system will will inform us when ready via a special URL.
Method: POST URL: https://tias-host-name/integration/api/v1/reply/job/{JOB-ID} Allowed Parameters: jobTag
The other system needs to know the ID of the job.
This information is used to correlate the status with the correct job.
The job-id have to be passed to the other system in the first phase (obtain via: context.jobRequestMessage().jobId() ).
|
If the other system failed to process the job, another URL should be used to let TIF know about the failure.
Method: POST
URL: https://tias-host-name/integration/api/v1/reply/job-fail/{JOB-ID}
This end point accepts some additional data in the request body in order to describe the problem.
{
"message" : "Some error message",
"details" : "Optional extra detailed error info"
}
The endpoint also accepts query string parameter called jobTag
, which can be used to attach additional tags to the job in question.
Javascript Executor Example
Below is a Javascript configuration illustrating the way of working.
if (context.input().isProcessingReply()) {
context.logger().info("!! Processing reply...... !!")
let data = context.input().data()
let data = new String(data.content(), data.encoding())
// INVOKE TX HERE
context.logger().info("Processing completed, data sent to TX...")
} else {
context.logger().info("About to invoke remote service....")
// THE JOB ID NEEDS TO BE PASSED TO REMOTE SERVICE
// THAT SERVICE WILL LATER CALL
// https://test2-tias-demo1.technia.com/reply/job/{job-id}
const jobId = context.jobRequestMessage().jobId();
context
.result()
.awaitingReply(true)
.message("Awaiting response from system X")
context.logger().info("Remote request for STEP conversion sent to CATIA Agent...")
}