Skip to content

jackie1in/graphql-subscription-sample

Repository files navigation

overview

技术 版本
spring-boot 2.0.0.RELEASE
graphql-java-tools 5.2.3
graphql-spring-boot-starter 5.0.1
spring-kafka 2.1.8.RELEASE
reactor-core 3.1.8.RELEASE

run

kafka server地址

localhost:9092

Hot publishers

Hot publishers, on the other hand, do not depend on any number of subscribers. They might start publishing data right away and would continue doing so whenever a new Subscriber comes in (in which case said subscriber would only see new elements emitted after it subscribed). For hot publishers, something does indeed happen before you subscribe.

UnicastProcessor<String> hotSource = UnicastProcessor.create();

Flux<String> hotFlux = hotSource.publish()
                                .autoConnect()
                                .map(String::toUpperCase);


hotFlux.subscribe(d -> System.out.println("Subscriber 1 to Hot Source: "+d));

hotSource.onNext("blue");
hotSource.onNext("green");

hotFlux.subscribe(d -> System.out.println("Subscriber 2 to Hot Source: "+d));

hotSource.onNext("orange");
hotSource.onNext("purple");
hotSource.onComplete();

output

Subscriber 1 to Hot Source: BLUE
Subscriber 1 to Hot Source: GREEN
Subscriber 1 to Hot Source: ORANGE
Subscriber 2 to Hot Source: ORANGE
Subscriber 1 to Hot Source: PURPLE
Subscriber 2 to Hot Source: PURPLE

网页访问

About

a example of graphql subscription with kafka

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published