Interacting asynchronously with REST APIs by using the RESTAsyncRequest and RESTAsyncResponse nodes
You can make REST requests and receive responses asynchronously by using RESTAsyncRequest and RESTAsyncResponse nodes in your message flow.
About this task
You might want to use asynchronous request-response processing with a backend server that has a high latency. Synchronous processing can result in many outstanding requests that require large numbers of threads to make simultaneous connections to the backend server. Asynchronous processing allows the response to be decoupled from the request.
You can use a pair of RESTAsyncRequest and RESTAsyncResponse nodes to interact with a REST API asynchronously. The paired nodes correlate responses against the original requests by using a unique identifier, which is specified on both nodes. Only one pair of nodes in an execution group can have the same unique identifier.
The RESTAsyncRequest node sends a REST request, and then returns control to the flow without waiting for a response. This action frees the request thread to handle further requests, while the response is handled by the paired RESTAsyncResponse node on a different thread and in a new transaction. This asynchronous functionality enables multiple outbound requests to be made almost in parallel because the outbound request is not blocked waiting for the response. The RESTAsyncResponse node can be in either the same flow or a separate flow, but it must be in the same integration server as its paired request node.
You can specify a timeout interval, so that if the whole request-response operation takes longer than the specified duration, the request is propagated to the Failure terminal on one of the paired nodes. The timeout interval applies to the interval that starts with the request being sent by the RESTAsyncRequest node, and ends with the response being completely received by the RESTAsyncResponse node.
For each request that the RESTAsyncRequest node processes, it uses a connection to send the request, and passes the connection to the paired RESTAsyncResponse node for the response. If the timeout interval is specified, the socket is closed if the interval expires. This closure ensures that a request gets only the correct response, and any response data for a request that is timed out is discarded.
The request-response processing is split between the RESTAsyncRequest node and the RESTAsyncResponse node. If a timeout occurs during the request phase of processing, the request and an exception are propagated to the Failure terminal of the RESTAsyncRequest node. Similarly, if a timeout occurs during the response phase of processing, an exception is propagated to the Failure terminal of the RESTAsyncResponse node. In most cases, the timeout would occur when waiting for a server response, in which case the Failure terminal of the RESTAsyncResponse node is used. In rare cases a timeout might occur when the request node sends data to the server. In this case, the Failure terminal of the RESTAsyncRequest node is used.
Procedure
Import a Swagger document or an OpenAPI 3.0 document and configure a RESTAsyncRequest node by completing the following steps: