3

I have a basic Spring Cloud Function application with two declared functions "lowercase" and "uppercase". If I create the application as a normal @SpringBootApplication and annotate both functions as @Beans (functional beans), everything works just fine. Both functions are exposed via seperate HTTP endpoints and I'm able to call the functions via:

  • curl localhost:8080/uppercase -H "Content-Type: text/plain" -d 'My input text'
  • curl localhost:8080/lowercase -H "Content-Type: text/plain" -d 'My input text'

Now I converted the application's main class to "functional form" to improve application startup time (as adviced in the official doc: http://cloud.spring.io/spring-cloud-function/multi/multi__functional_bean_definitions.html):

@SpringBootConfiguration
public class LambdaMicroserviceApplication implements ApplicationContextInitializer<GenericApplicationContext> {

    public Function<String, String> uppercase() {
        return String::toUpperCase;
    }

    public Function<String, String> lowercase() {
        return String::toLowerCase;
    }

    public static void main(String[] args) {
        FunctionalSpringApplication.run(LambdaMicroserviceApplication.class, args);
    }

    @Override
    public void initialize(GenericApplicationContext context) {
        context.registerBean("uppercase", FunctionRegistration.class,
            () -> new FunctionRegistration<>(uppercase())
                    .type(FunctionType.from(String.class).to(String.class)));
        context.registerBean("lowercase", FunctionRegistration.class,
            () -> new FunctionRegistration<>(lowercase())
                    .type(FunctionType.from(String.class).to(String.class)));
    }
}

Problem:

Only one single endpoint now gets exposed directly at the root path:

curl localhost:8080/ -H "Content-Type: text/plain" -d 'My input text'

It calls the "uppercase" function internally, regardless of registration order of the beans in the initialize function.

Question:

Is there a way to call both functions again via their dedicated endpoints: localhost:8080/uppercase and localhost:8080/lowercase?

Michael
  • 532
  • 1
  • 6
  • 15

1 Answers1

1

It turned out that this is actually a missing functionality in the functional form of Spring Cloud Function. It is now implemented in version 2.1.0.M1.

See: https://github.com/spring-cloud/spring-cloud-function/issues/293

Michael
  • 532
  • 1
  • 6
  • 15
  • Are you able to run this in AWS Lambda. For me this works fine till I have just one Function in my jar. I used "org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler::handleRequest" as Runtime Handler , and provided one of the function names in environment variables for "spring_cloud_function_definition" – Mayank Madhav Aug 22 '21 at 03:02