paulwong

          EVEN DRIVEN - SPRING CLOUD STREAM - @PollableBean for Reactive Suppliers

          Supplier beans, or functions that only publish messages in Spring Cloud Stream, are a bit special in that they aren't triggered by the receiving of events like Function or Consumer beans. This means that you often need a way to trigger them to be executed periodically.

          For imperative functions the framework by default "polls" a Supplier function every 1 second, but that duration is configurable using the spring.cloud.stream.poller.fixed-delay property.

          However, for reactive functions supplying a Flux it is only triggered once by default. This is because a Flux itself is potentially an infinite stream of events so in many cases it will only need to be triggered once. But don't worry, if you want to periodically trigger a reactive Supplier because you are producing a finite stream of events you can still do so using @PollableBean. This annotation then allows you to configure how often the function is triggered using the same spring.cloud.stream.poller.fixed-delay property!

          One example use case here could be periodically querying a data store and publishing each entry/row as an event. The number of rows in your data store is a finite number at any given time.

          Example code:

          @PollableBean 
          public Supplier<Flux<String>> stringSupplier() { return () -> Flux.just("foo","bar","baz"); }


          Reference:
          https://solace.community/discussion/360/pollablebean-for-reactive-suppliers-in-spring-cloud-stream

          posted on 2021-11-23 10:03 paulwong 閱讀(249) 評論(0)  編輯  收藏 所屬分類: SPRING CLOUDEVEN DRIVEN ARCHITECT

          主站蜘蛛池模板: 合江县| 芦山县| 桑日县| 濮阳市| 大丰市| 平乡县| 呈贡县| 永寿县| 巴林左旗| 会昌县| 平乐县| 崇阳县| 芜湖市| 铅山县| 金溪县| 保德县| 区。| 无锡市| 木里| 阜城县| 文昌市| 濮阳县| 迁西县| 新邵县| 竹溪县| 吴忠市| 福建省| 台北市| 泸水县| 泗洪县| 阳春市| 依兰县| 任丘市| 吉安县| 武隆县| 会宁县| 桂阳县| 沁阳市| 宁明县| 鄱阳县| 涡阳县|