linux-china / spring-cloud-function-demo

Spring cloud function with RSocket

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Cloud Function with RSocket

Expose cloud function with REST API & RSocket with R2DBC as backend.

Function signatures

  • RPC: Function<String, Mono>, Function<Mono, Mono>

public Function<String, String> uppercase() {
   return value -> value.toUpperCase();
}

public Function<Flux<String>, Flux<String>> reactiveUpperCase() {
	return flux -> flux.map(val -> val.toUpperCase());
}
  • request/stream: Function<String, Flux>
  • fire_and_forget/metadataPush: Function<String, Void>
public Consumer<Person> log() {
    return person -> {
        System.out.println("Received: " + person);
    };
}
	
public Function<Flux<?>, Mono<Void>> log() {
	return flux -> flux.map(..).filter(..).then();
}
  • channel: Function<Flux>, Flux

Demo function

@Controller
public class Greeter implements Function<String, Mono<String>> {

    @Override
    @MessageMapping("greeter")
    public Mono<String> apply(String name) {
        return Mono.just("Hello " + name);
    }
}

References

About

Spring cloud function with RSocket


Languages

Language:Java 93.6%Language:Just 6.4%