P_M
P_M

Reputation: 2942

Reactivestreams Subscriber not works with Spring Reactor Mono. Why?

I have a reactor.core.publisher.Mono variable and want to subscribe to org.reactivestreams.Subscriber, though it seems not works. I cannot get Why onNext method never called? I see onSubscribe method called fine. I could be mistaken, but as Mono implements Publisher, subscriber should work. Right?

@Test
    public void subscriberTest() {
        Mono<String> m = Mono.just("Hello!");
        Subscriber<String> s = new Subscriber<String>() {
            @Override
            public void onSubscribe(Subscription s) {
                System.out.println("Subscription "+s);
            }
            @Override
            public void onNext(String t) {
                System.out.println("onNext "+t);
            }
            @Override
            public void onError(Throwable t) {
                System.out.println("Throwable "+t);
            }
            @Override
            public void onComplete() {
                System.out.println("onComplete");
            }
        };
        m.subscribe(s);

        Mono<String> m1 = Mono.just("Bye!");
        m1.subscribe(System.out::println);
    }

Though the variable m1 subscription with method reference works fine. Here console output:

Subscription reactor.core.publisher.StrictSubscriber@4b168fa9
Bye!

Here I expect to see Hello! phrase too.

Upvotes: 1

Views: 2012

Answers (1)

Marcin Bukowiecki
Marcin Bukowiecki

Reputation: 410

https://www.reactive-streams.org/reactive-streams-1.0.0-javadoc/org/reactivestreams/Subscriber.html#onSubscribe-org.reactivestreams.Subscription- Here it is stated that No data will start flowing until Subscription.request(long) is invoked.

Upvotes: 2

Related Questions