Goal
From SAP PI/PO we already know the case of a sync/async bridge. Here I try to show a way how this can be realized with the SAP CPI (Integration Suite).
A sync/async bridge is used to link a synchronous sender with an asynchronously communicating recipient. The challenge is to keep the incoming connection open until the target system sends the response.
Flow of Sync/Async Bridge
Building
The very first thing I'll show here is our target image to get an overview. On the top left (
Sync: Entry) we receive the synchronous message from the sender. Then we forward this request via a Process Call to the bottom left (
Async: Request). We then start our wait step as a loop at the top right (
Sync: Wait for Response). There we try to read the response from the datastore as soon as it is available. If no response is available, the process is repeated. At the bottom right (
Async: Response) we accept all incoming responses and write them to the datastore. After the response is received, it is automatically transferred to the sender and the process is finished.
Flow how it should look in the end
Sync: Entry
Here we only define the input for the synchronous sender and link the "Async: Request" via a "Process Call" and the "Sync: Wait for Response" via a "Looping Process Call".
Sync: Entry Elements
For the Looping Call we set the following settings:
Looping Process Call - Settings
Hint: The "Max. Number of Iterations" must be multiplied by our sleep step of 1 second. So the flow will iterate for 3 minutes until it stops with an exception. The maximum should be 5 minutes.
Sync: Wait for Response
This "local integration process" is executed repetitively by a loop. With each iteration, an attempt is made to read the corresponding response message of the asynchronous system from the DateStore. For this we use the MessageId as reference.
Then we check, in the "Router", whether an entry was found in the DataStore. If no entry is found, a Groovy script executes a sleep of 1 second, because there is currently no other way to configure the waiting time between the iterations.
Sync: Wait for Response Elements
Settings for "Find Response Message"
Settings for "Router"
/*
Function: Sleep for 1 Second
Author: Robert Fels / Contiva GmbH / www.contiva.com / robert.fels@contiva.com
Version 1.0
*/
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
sleep(1000);
return message;
}
Code for "Wait for 1sec"
Async: Request
This "Local Integration Process" is used to send the request message to the asynchronous system. Before the message is sent, we insert a
reference so that the response message can later be assigned to the current process. For this we use the
${header.SAP_MessageProcessingLogID}. This is automatically generated by SAP for each incoming synchronous message and is unique. Of course you can also transfer it via a specific mapping.
Async: Request Elements
Setting of "Set Reference"
Async: Response
We catch the Asynchronous Response with an "Integration Process" and not a "Local Integration Process". This could also theoretically be placed in its own flow and is instantiated specifically when the asynchronous system calls with the response. We take the reference out of the payload and write it into a header value in order to be able to set the "EntryID" when writing to the DataStore.
Async: Response Elements
Settings of "Get Reference"
Settings of "Write Response"
Conclusion
I hope this helps you to successfully build a sync/async bridge in the SAP CPI. At the moment I don't see any better or other way to implement it.
It would be nice if we could configure the waiting time between the iterations already in the loop call instead of doing this via a Groovy script, but unfortunately this is currently not implemented and possible.
You should also think about an exception handling in case of an timeout on the synchronous side. Then maybe the asynchronous system should be informed about a rollback.
I am glad if you follow me on SAP People (
robertfels). If you have any ideas, suggestions or questions, please feel free to contact me in the comments.
Be also sure to check out the other posts and follow the
SAP Integration Suite Environment topic page,
ask and answer questions or read other
posts on the topic.
Cheers
Robert Fels