0

I'm trying to map a Supplier Bean to an Azure function using Spring Cloud Function 2.0, but I need to extend AzureSpringBootRequestHandler, which seems to only support functions with an input parameter and a return value. class AzureSpringBootRequestHandler has two type parameters: input and output, and AzureSpringBootRequestHandler.handleRequest() also expects the input parameter.

@Bean
public Supplier<List<String>> foo() {
    return () -> Arrays.asList("foo1", "foo2");
}

/////

class FooFunction extends AzureSpringBootRequestHandler<Void, List<String>> {
    @FunctionName("foo")
    List<String> foo(@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST},
        authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional<String>> request,
                               ExecutionContext context) {
        return handleRequest(null, context);
    }
}

The code above causes NPE at reactor.core.publisher.FluxJust.(FluxJust.java:60)

Changing the @Bean return type to Function<Void, List<String>> causes IllegalStateException "No function defined with name=foo" at AzureSpringFunctionInitializer.lookup

Adding a dummy int parameter works.

P.S Ideally I don't even need the return value so instead of Supplier I would make it a Runnable, but this seems completely unsupported.

Any help would be appreciated.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
Hagai Cibulski
  • 4,421
  • 3
  • 20
  • 23
  • In the context of azure functions, as of now there is only support for basic types and POJOs for inputs and return values [functions-reference-java#data-type-support](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java#data-type-support). AzureSpringBootRequestHandler is wrapping an azure function. It is possible there might be an issue in the wrapper. – Pragna Gopa Feb 22 '19 at 01:29
  • 1
    This appears to be a missing feature. Could you please raise an issue in - https://github.com/spring-cloud/spring-cloud-function/issues – Oleg Zhurakousky Feb 22 '19 at 07:44
  • Is there any update yet? I have a familar issue that I can´t solve. – O. Schnieders Aug 30 '19 at 21:08

1 Answers1

2

Support for supplier and consumer is added in Spring Cloud Function 3.0.0. This is currently still a milestone.

More information this change.

I solved the issue, using Spring Cloud Function 2.x, by changing the signature of AzureSpringBootRequestHandler to use Optional as follows:

public class SomeFunction extends AzureSpringBootRequestHandler<Optional<?>, List<Foo>> {

    @FunctionName("some-function")
    public List<Device> execute(@HttpTrigger(name = "req",
            methods = {HttpMethod.GET},
            authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Void> request,
            ExecutionContext context) {
        return handleRequest(Optional.empty(), context);
    }
}

You'll also have to change the type of your bean to match this:

@Bean(name="some-function")
public Function<Optional<?>, List<Device>> someFunction() {
    return v -> fooService.bar();
}