{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • API Design /
avatar image
0
Question by Ashish Pokharel · Aug 31, 2018 at 01:37 AM · 766 Views asynchronoussynchronous

Converting asynchronous backend service to synchronous request

Hi All,

We have an asynchronous service which needs to be serviced as synchronous API to a front-end application. The service responds with a 201 immediately with a requestId and eventually with actual response on a callbackUrl with the same requestId in response body. The callbackUrl is provided as part of request and be another Apigee endpoint of course. We have a need to make this service synchronous using Apigee. API will make the initial call and

- return an error code if anything other than 201 is received

- if 201 is received with requestId, request will be blocked until a response is received in callbackUrl for that responseId OR a timeout is hit. Delayed callback response will need to be ignored.

I have seen several references in the forum to make service callout asynchronously and later wait for responses. However, I am having hard time finding an API example to achieve what we need.

Thanks in advance, Ashish

Comment
Add comment Show 5
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Siddharth Barahalikar   · Aug 31, 2018 at 04:58 AM 0
Link

HI @Ashish Pokharel, maybe we can use a Service Callout(SC) Policy. A SC policy with Response tag is an synchronous call. If you omit he Response tag, the SC will fire a call & proceed forward without any response.

In your case use the Response tag & in SC also set the timeout in milliseconds.

<ServiceCalloutasync="false"continueOnError="false"enabled="true"name="SC-1">
	<DisplayName>SC</DisplayName>
	<Response>calloutResponse</Response>
	<Timeout>60000</Timeout>
	<HTTPTargetConnection>
		<URL>http://example.com</URL>
	</HTTPTargetConnection>
</ServiceCallout>

After SC policy, use calloutResponse.status.code flow variable to check the status code & raise an error if required.

avatar image Ashish Pokharel · Aug 31, 2018 at 11:28 AM 0
Link

@Siddharth Barahalikar thanks but that may not be what we need. I am ok to wait for intermediate response synchronously from backend. If that is 201, I will get a requestId. Now, until the backend responds asynchronously (meaning it will be a different POST call from backend to a callbackUrl we can set from Apigee) I have to block original request and wait for a response for that particular requestId so I can attach the final response from backend tonoriginal request. So, some questions are

1. What callbackUrl will I set to get response

2. How will I block original request and wait for callback respose as response is a different POST from backend

3. How do I respond to the right requestId only

Thanks, Ashish

avatar image Siddharth Barahalikar Ashish Pokharel   · Aug 31, 2018 at 11:37 AM 0
Link

Maybe we need to use Nodejs/Javascript. Have a look at,

https://community.apigee.com/articles/2340/asynchronous-http-requests-in-an-api-proxy.html

https://docs.apigee.com/api-platform/reference/javascript-object-model#makingjavascriptcalloutswithhttpclient

avatar image Ashish Pokharel Siddharth Barahalikar · Sep 01, 2018 at 03:59 PM 0
Link

IDK, I am not able to see a convincing solution here. To me, these articles read how make a call asynchronously to more or less a synchronous backend so calls could be parallelized and later synchronized. That't not really what we need. We are looking for implementation of this facade described back in 2012

https://www.slideshare.net/apigee/essential-api-facade-patterns-synchronous-to-asynchronous-conversion-episode-4

I actually guessed this was a piece of cake but is becoming tricky :)

avatar image Ashish Pokharel · Aug 31, 2018 at 12:15 PM 0
Link

Will do. Thanks! I noticed a slideshare presentation by Santanu Dey which explains this facade pattern but has no code reference :(

Close

0 Answers

  • Sort: 

Follow this Question

Answers Answers and Comments

55 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Security options to protect callback 1 Answer

timeout for asynchronous response 2 Answers

Advice on changing from ESB to API Approach: Calling a REST API Asynchronously makes it not a REST API? 1 Answer

How to make Syncronus/parellel calls on Apigee using other then Node js approach as it is not feasible presently on our Apigee infra 1 Answer

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges