azure-functions-java-worker icon indicating copy to clipboard operation
azure-functions-java-worker copied to clipboard

Add support for functions that return a Future

Open pragnagopa opened this issue 7 years ago • 12 comments

Add support for functions to run async. For example

 @FunctionName("HttpTrigger-JavaAsync")
    public CompletableFuture<HttpResponseMessage> runAsync(
            @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context)

Java worker should inspect function method signature, if it returns a Future invoke it asynchronously and if not invoke the method synchronously.

pragnagopa avatar Nov 19 '18 19:11 pragnagopa

@anuchandy @selvasingh

pragnagopa avatar Nov 19 '18 19:11 pragnagopa

@pragnagopa was this ever implemented?

daniel-rocha avatar Apr 12 '19 03:04 daniel-rocha

Not yet. We are tracking this as a feature request.

pragnagopa avatar Apr 15 '19 15:04 pragnagopa

@pragnagopa @amamounelsayed

Is it possible to receive async responses with azure functions? Because I don't receive any errors when the mail can not be sent which I receive on my local environment (e.g. 500 - Internal Server error, when password is wrong).

Source from: https://quarkus.io/guides/mailer#sending-simple-emails

GET
@Path("/async")
public CompletionStage<Response> sendASimpleEmailAsync() {
    return reactiveMailer.send(
            Mail.withText("[email protected]", "A reactive email from quarkus", "This is my body"))
            .subscribeAsCompletionStage()
            .thenApply(x -> Response.accepted().build());
}

Kondamon avatar Jun 13 '20 21:06 Kondamon

How about returning Mono or Flux?

vovikdrg avatar Aug 29 '21 13:08 vovikdrg

Hi @amamounelsayed ,

We have users asking about this capability in spring-cloud-function and It would be helpful to get an idea where this feature request stands wrt to the overall product roadmap / backlog. Can you give an update on this?

Thanks.

onobc avatar Mar 23 '22 14:03 onobc

Hi @onobc , thanks for reaching out. I would like to understand more how customer will be using mono/flux returned by functions. Do we have some solid user cases that I can take a look and think about. Thanks.

kaibocai avatar May 26 '22 18:05 kaibocai

Hi @kaibocai , I have been out on PTO and have not had a chance to get the requested info. I just wanted to reach out and tell you thanks for the reply and I will get you that info sometime in the next week.

onobc avatar May 31 '22 03:05 onobc

Hi @kaibocai , one specific scenario is user sending a JMS message for each item in the returned flux. Other than that I believe it is mostly Reactive enthusiasts wanting their Reactive APIs.

I do think there is also another not-so-obvious use case - the use of non-blocking APIs in the function implementation code. Currently, there is not much benefit for using a Reactive API w/in the function logic as ultimately it will be blocked upon function invocation. Adding this support would also expand the Reactive footprint[^1] of the function call - leading to more "Reactive benefits". Here are a couple of related issues (not directly to Reactive but more of non-blocking in general):

  • https://github.com/microsoft/durabletask-java/issues/3
  • https://github.com/microsoft/durabletask-java/issues/2 currently as there is no way

[^1]: Sidenote - I visualize the Reactive code surrounded with a "reactive membrane" that separates it from the other imperative code. The bigger this membrane, the bigger the reactive footprint and therefore the more benefits we receive from "buying into" reactive .

onobc avatar Jun 14 '22 22:06 onobc

How about returning Mono or Flux?

@pragnagopa @amamounelsayed

Is it possible to receive async responses with azure functions? Because I don't receive any errors when the mail can not be sent which I receive on my local environment (e.g. 500 - Internal Server error, when password is wrong).

Source from: https://quarkus.io/guides/mailer#sending-simple-emails

GET
@Path("/async")
public CompletionStage<Response> sendASimpleEmailAsync() {
    return reactiveMailer.send(
            Mail.withText("[email protected]", "A reactive email from quarkus", "This is my body"))
            .subscribeAsCompletionStage()
            .thenApply(x -> Response.accepted().build());
}

Hi @Kondamon , can you provide the full code of your function code. It will help me understand the full picture. Thanks a lot.

kaibocai avatar Sep 12 '22 21:09 kaibocai

@kaibocai in my case I‘m not using async anymore since there were no benefits in my use case. The example was from https://quarkus.io/guides/mailer-reference

Kondamon avatar Sep 13 '22 07:09 Kondamon

Any fix for returning HttpResponseMessage as Mono<HttpResponseMessage> ?

rjavaria avatar Mar 08 '24 13:03 rjavaria