Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member786889
Discoverer
Dear Community

Introduction:

Message processing log (MPL) is one of very demanded topics in SAP CPI, MPL is an invaluable source of information for monitoring and troubleshooting, as compared to SAP PIPO retry of a message in CPI is different and limited with JMS Ques or data source. There are many blogs available to retry messages using JMS Ques, sometimes it is required to download hundreds of messages for reprocess.

I would like to share an approach to implement an iflow, which can be used to download multiple messages and resend using postman/or another iflow.

There is a way to export CPI message processing log for failed messages in mass with error details by using SAP CPI API.

Scenario:

Download multiple messages into any local SFTP Directory (connected backend of Cloud Connector) for a particular iflow for a particular period using SAP CPI API Calls.

Refer below link to understand SAP CPI API Calls for different requirements like access message logs, access message attachments etc.,

https://api.sap.com/api/MessageProcessingLogs/resource/Logs


                                                SAP CPI API

The below are the three important API End points can be utilised together to achieve the requirement.

Iflow Message List Request End Point API: This API End point can be used to get list of messages processed for a particular period.
---------------------------------------------------------------------------------------------------------------------------------
https://<TENANT URL>/api/v1/MessageProcessingLogs?%24select=IntegrationArtifact%2CStatus%2CLogStart%2CLogEnd&$filter=IntegrationArtifact/Id eq 'IFLOW_NAME' and Status eq 'FAILED' and  LogStart ge datetime'2023-05-05T09:00:00.000' and  LogEnd le datetime'2023-05-05T11:00:00.000'


 

Screenshot of postman call for the above API Call



MESSAGE LIST BY IFLOW-POSTMAN

 

Iflow Attachment List by Message GUID API Call : this endpoint can be used to get list of attachments for a particular message id.
----------------------------------------------------------------------------------------------------------------------
https://<TENANT URL>/api/v1/MessageProcessingLogs('MESSAGE GUID CAN BE GET FROM ABOVE END POINT URL ')/Attachments


MESSAGE LIST BY GUID-POSTMAN


Iflow Attachment by Attachment GUID API : This end point can be used to get attachment/payload for a particular message guid
-----------------------------------------------------------------------------------------------------------------------------------------
https://<TENANT URL>/api/v1/MessageProcessingLogAttachments('3838363037306666747............ATTACHEMNT ID................... GET FROM MESSAGE GUID URL ................32393138346232')/$value

Need to use 3 Request Reply calls to achieve the above in CPI


Design of the Iflow


 

Below are the design flow steps

  1. First Request Reply to get the list of Messages for a Iflow for particular period (with odata filters can be used in the end point URL to achieve this)

  2. Groovy Script to replace name spaces from xml response of first request reply


  3. import com.sap.gateway.ip.core.customdev.util.Message;
    import java.util.HashMap;
    def Message processData(Message message)
    {
    def body=message.getBody(java.lang.String) as String;

    body=body.replace("<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" xml:base=\"https://<tenant URL>/api/v1/\">","<feed>");


    body=body.replace("<m:","<");
    body=body.replace("<d:","<");
    body=body.replace("</m:","</");
    body=body.replace("</d:","</");
    body=body.replace("m:type","type");

    message.setBody(body);
    def messageLog = messageLogFactory.getMessageLog(message);
    if(messageLog != null){
    messageLog.setStringProperty("Logging#1", "1 Iflow Message List")
    messageLog.addAttachmentAsString("1 Iflow Message List:", body, "text/plain");
    //def MessageID = message.getHeaders().get("orderNo");
    //messageLog.addCustomHeaderProperty("orderNo",OrderNumber);
    }
    return message;
    }


  4. Iterating Splitter to split multiple messages by element <entry>

  5.  Process Call for looping.

  6. Use Content modifier to capture.

     <id><TENANT>/api/v1/MessageProcessingLogs('AGRUyCO9Zlsi70VYD-g6uN4id6hd')</id>

    XPATH <id> where end point url of next request reply



  7. Request reply to get list of attachments against above Message ID for the specified Iflow

  8. Again, Groovy Script to replace names space.

  9. Content Modifier to capture xpath id but this time to capture attachment end point URL.

     <entry>

            <id><TENANT>/api/v1/MessageProcessingLogAttachments('38383630.........message attachment id............974795f37332f32383762393463342d396339352d343266622d616438332d316530393532393138346232')</id>

            <title type="text">MessageProcessingLogAttachments</title>



  10. Last Request reply to capture the message with the above URL (need to add

    /$value)




Note : The setup can be used for retry mechanism for any iflow.

Conclusion:
We just saw how to configure the SAP CPI API calls to get Messages List for an iflow, to get attachments list for a Message ID and to get attachment.

To be very clear: This blog post is specifically about using of SAP CPI API to deal with multiple payloads and another mechanism of retry system.

If you’re interested in learning more about the SAP API Calls, I recommend reading deepakgovardhanrao.deshpande blog post: SAP Cloud Integration – Step towards Building API Based Integrations

If you're interested in learning more about the message retry system, I recommend reading s1985 blog post :Message retry using Process Direct and Data Store in SAP CPI
  • SAP Managed Tags: