最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactive programming - Sinks.many().multicast() only 1 subscriber receives events - Stack Overflow

programmeradmin4浏览0评论

I am new to reactive programming. And try to understand how the sinks and flux works.

Following an instruction with code

import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;

public class SinkExample {

  public static void main(String[] args) {
Sinks.Many<String> sink = Sinks.many().multicast().onBackpressureBuffer();
    Flux<String> flux = sink.asFlux();

    sink.tryEmitNext("Stock price updated!");
    sink.tryEmitNext("Go checkout");

    flux.subscribe(price -> System.out.println("Client 1 received: " + price));
    flux.subscribe(price -> System.out.println("Client 2 received: " + price));
  }
}

I should expect both my flux subscriber receives 2 events.

Client 1 received: Stock price updated!
Client 1 received: Go checkout
Client 2 received: Stock price updated!
Client 2 received: Go checkout

But when I run the program. I only get 1 subscriber(Client 1) receives the events

Client 1 received: Stock price updated!
Client 1 received: Go checkout

Does anyone know why?

发布评论

评论列表(0)

  1. 暂无评论