How does one implement the asynchronous pattern in a child Logic App? - azure-logic-apps

Logic Apps support calling other Logic Apps with a special action:
They support something they call the "asynchronous pattern" through this option:
where the called Logic App returns a 202 (Accepted) and the calling Logic App will implicitly poll the same trigger URL until completion is signalled using 200 (OK).
How are you supposed to implement this pattern in the called Logic App? I can send a response, but once that's happened, I can't send a response again. Or can I? If so; how? How do you specify the polling URL?

In the response action, you could enable 'Asynchronous Response'. See the dialog below
[]

Related

Logic App Response action to return status code reason

When a Logic App uses the Request trigger to receive inbound requests and the Response built-in action to send the response back to the caller, the Response action must include the Status Code - 200, 400, 401, etc.
Along with the Status Code, I'd like to be able to send the reason of the status code, in the same way it can be done in the API Management by using the set-status policy.
Is it possible at all to specify the status code reason in the Logic App Response action?
Is it possible at all to specify the status code reason in the Logic App Response action?
No it is not possible using Logic Apps.
But if its business need, as an alternative, You can define it in the response body at your client application and you need to pass the response body as a reason.
You can submit a feature request here in more detail.

Logic app doe snot resume after calling webhook

I have a logic app that calls API endpoint through APIM. when I call endpoint in the logic app using the webhook connector, webhook keeps running and doe snot resume logic app.
While if I tried the same API endpoint through postman, it respond back within 3-5 seconds.
Below is the screenshot.
Not sure if i am missing anything.
This is outside the intended use of the webhook http task.
https://learn.microsoft.com/en-us/azure/connectors/connectors-native-webhook
You'll want to use the regular http post task, but you can extend the timeout in the settings to accommodate your long-running http call.
(click the triple dots in the top-right, then utilize the "Action Timeout" setting).
You could also try disabling asyncronous behavior:
https://learn.microsoft.com/en-us/azure/connectors/connectors-native-http#avoid-http-timeouts-for-long-running-tasks
If the logic app still times out, you will probably need to design a different solution.

Call http REST api from Flink using Asynchronous I/O

i have to fetch data from Rest API from flink process element in every data fetch from the stream, how can i achive that, i couldnt find enough meterials to call the Rest service asynchronously. please help me with some sample articles.
All the job is happening inside the asyncInvoke of the RichAsyncFunction. So, to be able to call REST service, You need to use some async HTTP client (technically it could be a synchronous client but this doesn't make sense). An example of async http client usage can be found here.
So, when You execute the async request all You need to do, is to call resultFuture.complete in Your request handler, so that the result is passed downstream in Flink.

Real time with AngularJs & Yii2

I'm developing a Yii2 REST API, with AngularJS for the frontend to consume.
I need a way to implement real time approach, e.g. for a chat, or to make some real time notifications.
Is this possible, how to achieve? I been reading about Ratchet, Socket.io and some other things, but I couldn't figure out how to make them fit together for REST or if this is the way to go.
Any advice would be appreciate.
You have a few options here.
Short / Long Polling (use setTimeout)
app.controller("MyController", function($scope, $timeout, $http) {
$scope.messages = [];
$timeout(callAtTimeout, 3000);
function callAtTimeout() {
console.log("Timeout occurred");
$http.get('PATH TO RESOURCE TO GET NEW MESSAGES').then(
function(res) { // update $scope.messages etc... },
function(err) { // handle error }
);
}
});
For both short and long polling on client side, you send request, wait to get a response back, then wait 3 seconds and fire again.
Short/Long polling works differently on the server side. Short polling will just return a response immediately - whether something has changed or not. Long polling, you hold the connection open and when there is a change, then you return the data. Beware of keeping too many connections open.
Socket.io (websockets)
I would recommend that you implement websockets using either something like node.js on your own web server or a hosted solution like Firebase.
The thing with Firebase is that from PHP, you can send a post request to a REST endpoint on the firebase server. Your javascript can connect to that endpoint and listen for changes and update the dom accordingly. It is possibly the simplest of all to implement.
I personally wouldnt use PHP for socket programming but it can be done.
To have real-time updates on your website, you can implement one of the following approaches depending on your requirement and how fast you need to update your frontend component.
Using a websocket
You can use a library like https://github.com/consik/yii2-websocket to implement it with Yii2. But this will act as a separate service from your REST API. Therefore you have to make sure that proper security practices are applied.
Running an Angular function with a timeout
You can continuously poll an endpoint of the REST API with a timeout of few milliseconds to receive updated values.
The second approach will create many requests to the API which will increase the server load. Therefore my preferred approach is using a websocket.

Preventing similar POST requests with AngularJS

I am currently building a dashboard page with multiple widgets. Those widgets retrieve their data with REST calls ($resource). A few widgets make similar calls and I don't want to DDOS our server so I am looking for a way to make a call only once and resolve all similar requests with the same response.
Since I am restricted to using POST requests only, I cannot use the cache option that $resource offers. This seems to be doing exactly what I want but only for GET requests.
I was thinking along the lines of using a http interceptor to queue similar POST requests, fire only one of them and resolving them all when the first one gets its response.
However, I cannot seem to put the pieces together so any help is appreciated. I am open to other options.
Kind regards,
Tim
Services in AngularJS are singletons, so a solution would be to store the response in the service, as a variable. Then next time you'll do the request, previously check if the variable is null, if it's not you wrap it in a promise and returned it. If it's null, then you do the request, and store the response for the next call.
You can also either use this in your request service or in your interceptor service.
I hope I helped !
Refactor your widgets to depend on a service (singleton).
This service should either poll the server via XHR, or get server push via websocket for updates.
If polling, look into server side caching and etags.

Resources