Azure / azure-functions-java-library

Contains annotations for writing Azure Functions in Java
MIT License
42 stars 42 forks source link

Azure Function coded with spring-cloud-function-adapter-azure SDK cannot return value of form of Mono/Flux. #159

Open alain-marcel opened 2 years ago

alain-marcel commented 2 years ago

We are using the spring-cloud-function-adapter-azure SDK to build our function. We expect the return value to be in the form of Mono and Flux, but the we cannot return the corresponding value.

The code link provided by the official website: Getting started with Spring Cloud Function in Azure | Microsoft Docs After checking the code provided by the official website, we found that only the return value in the HTTP response format was provided as follows:

public class HelloHandler extends FunctionInvoker<User, Greeting> {

    @FunctionName("hello")
    public HttpResponseMessage execute(
        @HttpTrigger(name = "request", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<User>> request,
        ExecutionContext context) {
        User user = request.getBody()
                           .filter((u -> u.getName() != null))
                           .orElseGet(() -> new User(
                               request.getQueryParameters()
                                      .getOrDefault("name", "world")));
        context.getLogger().info("Greeting user name: " + user.getName());
        return request
            .createResponseBuilder(HttpStatus.OK)
            .body(handleRequest(user, context))
            .header("Content-Type", "application/json")
            .build();
    }}

I did not find the return form of Mono and Flux. The return format that we wanted is as follows:

public class HelloHandler extends FunctionInvoker<User, Mono<Greeting>> {

    @FunctionName("hello")
    public HttpResponseMessage execute(
        @HttpTrigger(name = "request", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<User>> request,
        ExecutionContext context) {
          // ...
}

We want to know whether the return of Mono and Flux is supported on Azure, because the customer found that .NET can return the corresponding value, as follows:

[FunctionName("Httpxample")]
public static async Task<IActionResult> Run(
   [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HtppREquest req,
   Iloogger log
   )

Please confirm the feasibility of this request. Thank you very much for your help.

kaibocai commented 1 year ago

Hi @alain-marcel , thanks for reaching out and sorry for the late reply. Did you still have this issue?

alain-marcel commented 1 year ago

Hi The issue is still not resolve. In fact, it is more a limitation than an issue. The question is : is it possible with an azure function written in java with rective.io ? I think this behavior exist with .Net. I think it is possible in .Net because azure is managed by .Net and there is a continuity with user code in the azure function and the framework.

I represent here my wish:

I have an HttpTrigger an azure function written in java with rective.io. We have to write the reactive stream in response to the http trigger request, and terminate the stream with a block() reactive operation It is preferable to call block() with a timeout because if trouble, the azure function will wait indefinitely.

Drawback : the call to block(timeout) is done at server side (in the azure function).

Wish : it would be far better to call this block(timeout) at client side (equivalent to start the reactive stream from client side and control timeout from client side

De : kaibocai @.> Envoyé : jeudi 5 janvier 2023 18:33 À : Azure/azure-functions-java-library @.> Cc : MARCEL Alain @.>; Mention @.> Objet : Re: [Azure/azure-functions-java-library] Azure Function coded with spring-cloud-function-adapter-azure SDK cannot return value of form of Mono/Flux. (Issue #159)

Hi @alain-marcelhttps://github.com/alain-marcel , thanks for reaching out and sorry for the late reply. Did you still have this issue?

— Reply to this email directly, view it on GitHubhttps://github.com/Azure/azure-functions-java-library/issues/159#issuecomment-1372521572, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALBYLYCZHOGB7BXQBPYZCDDWQ4AUZANCNFSM5H43HEUA. You are receiving this because you were mentioned.Message ID: @.**@.>>

kaibocai commented 1 year ago

Hi @alain-marcel , I am investigating the possible solution for non-blocking/reactive invocation, I am trying to understand how .NET is supporting this. It will be great if you can share any docs on .NET about this feature.

Attach the sample issue from the java worker repo: https://github.com/Azure/azure-functions-java-worker/issues/244

alain-marcel commented 1 year ago

Hi kaibocai

I do not have any documentation on .Net. But AWS does the “non-blocking/reactive invocation” with its java server function. I have no documentation on that. Regards.

De : kaibocai @.> Envoyé : mardi 17 janvier 2023 19:31 À : Azure/azure-functions-java-library @.> Cc : MARCEL Alain @.>; Mention @.> Objet : Re: [Azure/azure-functions-java-library] Azure Function coded with spring-cloud-function-adapter-azure SDK cannot return value of form of Mono/Flux. (Issue #159)

Hi @alain-marcelhttps://github.com/alain-marcel , I am investigating the possible solution for non-blocking/reactive invocation, I am trying to understand how .NET is supporting this. It will be great if you can share any docs on .NET about this feature.

Attach the sample issue from the java worker repo: Azure/azure-functions-java-worker#244https://github.com/Azure/azure-functions-java-worker/issues/244

— Reply to this email directly, view it on GitHubhttps://github.com/Azure/azure-functions-java-library/issues/159#issuecomment-1385854676, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALBYLYBOIVXYBGTIICMI4I3WS3QPRANCNFSM5H43HEUA. You are receiving this because you were mentioned.Message ID: @.**@.>>