Datapower Parallel call -_post xml

140 views Asked by At

We have a requirement where there are two backends.

First, we call backend-1 where consumer is sending json and we are converting it to query params/GET. Heare I am using dp-open url to call service and get response. After getting the response from first backend I am storing in datapower context variable. if we receive ten tokens from backend-1 we have to call second backend ten times parallelly with the tokens received from backend 1. Here backend-2 is post/xml body.

Can you please help in achieving this or provide the way to call parallelly with backend2.

Afet receiving the first response. I am using for each dp-open url for all the tokens received, I am using Asynch on and event sych action but still the calls are going at a time but the response we are getting sequential.

1

There are 1 answers

0
ByteBender On

Use dp:iterate to loop through the tokens obtained from the first backend response and dp:threads to perform parallel calls to the second backend with each token.

Below you can find i custom example.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp">
  
  <!-- Call the first backend -->
  <xsl:template match="/">
    <!-- Make the first backend call -->
    <dp:open url="http://first-backend-url">
      <dp:http-request method="GET" />
    </dp:open>
  </xsl:template>
  
  <!-- Process the first backend response -->
  <xsl:template match="dp:response">
    <!-- Extract tokens from the response -->
    <xsl:variable name="tokens" select="dp:variable('var://context/first-backend-response/tokens')" />
    
    <!-- Use dp:iterate to loop through tokens -->
    <dp:iterate select="$tokens" item="token">
      <!-- Use dp:threads for parallel calls to the second backend -->
      <dp:threads>
        <dp:thread>
          <!-- Make the second backend call with the current token -->
          <dp:open url="http://second-backend-url">
            <dp:http-request method="POST">
              <dp:http-request-body>
                <xsl:copy-of select="token" />
              </dp:http-request-body>
            </dp:http-request>
          </dp:open>
        </dp:thread>
      </dp:threads>
    </dp:iterate>
  </xsl:template>
  
  <!-- Combine and generate the final response -->
  <xsl:template match="dp:response">
    <!-- Combine results from parallel calls -->
    <!-- Generate the final response -->
  </xsl:template>
</xsl:stylesheet>