1

flink playground gives a demo as below:

public final class GreeterAppServer {

  public static void main(String[] args) {
    final StatefulFunctions functions = new StatefulFunctions();
    functions.withStatefulFunction(UserFn.SPEC);
    functions.withStatefulFunction(GreetingsFn.SPEC);

    final RequestReplyHandler requestReplyHandler = functions.requestReplyHandler();
    final Undertow httpServer =
        Undertow.builder()
            .addHttpListener(1108, "0.0.0.0")
            .setHandler(new UndertowHttpHandler(requestReplyHandler))
            .build();
    httpServer.start();
  }

how to access the function by a http request? post?get?

Ruli
  • 2,592
  • 12
  • 30
  • 40
宋之一
  • 11
  • 2
  • 1
    You can find the complete documentation at statefun.io, and in the playground try `docker-compose up` – Igal Jan 13 '22 at 16:44
  • statefun master will access the http server's endpoint specified in `urlPathTemplate` of `io.statefun.endpoints.v2/http` spec in `module.yaml`. it's going to be a POST request because master needs to use request body to send byte array – mangusta Sep 30 '22 at 07:51

1 Answers1

1

When you set your stateful function like this

functions.withStatefulFunction(UserFn.SPEC); 

you actually register your function as a handler to http server.

Next thing you have to do is to define which endpoint your function will be using.

  static final TypeName TYPENAME = TypeName.typeNameOf("greeter.fns", "user");
  static final StatefulFunctionSpec SPEC =
      StatefulFunctionSpec.builder(TYPENAME)
          .withValueSpecs(SEEN_COUNT, SEEN_TIMESTAMP_MS)
          .withSupplier(UserFn::new)
          .build();

In the example above, stateful function is registered to the endpoint greeter.fns/user. Ref: https://github.com/apache/flink-statefun-playground/blob/main/java/greeter/src/main/java/org/apache/flink/statefun/playground/java/greeter/UserFn.java

This should also be defined in your module.yaml file as below. Ref: https://github.com/apache/flink-statefun-playground/blob/main/java/greeter/module.yaml

functions: greeter.fns/*

Finally, you configure your module.yaml as an environment in your docker-compose.yml. Ref: https://github.com/apache/flink-statefun-playground/blob/main/java/greeter/docker-compose.yml

volumes:
  - ./module.yaml:/module.yaml
misterbaykal
  • 522
  • 5
  • 15