Azure / azure-functions-java-worker

Java runtime and core types for Microsoft Azure Functions
MIT License
87 stars 54 forks source link

Add support for functions that return a Future #244

Open pragnagopa opened 5 years ago

pragnagopa commented 5 years ago

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 commented 5 years ago

@anuchandy @selvasingh

daniel-rocha commented 5 years ago

@pragnagopa was this ever implemented?

pragnagopa commented 5 years ago

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

Kondamon commented 4 years ago

@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("to@acme.org", "A reactive email from quarkus", "This is my body"))
            .subscribeAsCompletionStage()
            .thenApply(x -> Response.accepted().build());
}
vovikdrg commented 3 years ago

How about returning Mono or Flux?

onobc commented 2 years ago

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.

kaibocai commented 2 years ago

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.

onobc commented 2 years ago

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 commented 2 years ago

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):

[^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 .

kaibocai commented 2 years ago

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("to@acme.org", "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.

Kondamon commented 2 years ago

@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

rjavaria commented 6 months ago

Any fix for returning HttpResponseMessage as Mono ?