Mono.zip(
Mono.fromCallable(() -> queueDao.getNumberOfMessageInQueue(cartDaemonUrl)),
Mono.fromCallable(() -> queueDao.getNumberOfMessageInQueue(orderConfirmationDaemonUrl))
//ono.fromCallable(()->queueDao.getNumberOfMessageInQueue(cartDaemonUrl))
)
.map(T -> updateQueueCountToDb(T.getT1().block(), T.getT2().block())).
doOnSuccess(row -> log.info("Queue info inserted into db rows ")).
doOnError(e -> log.error("Error while inserting data stacktrace{}", e.getStackTrace()));
我无法弄清楚控件为什么不输入updateQueueCountToDb方法。我还在该方法中添加了日志,即使这些日志未在控制台中打印。
答案 0 :(得分:0)
继续@Jesper给出的评论是正确的,您必须订阅反应性流才能使它们生效,否则,我们只是在构建期望数据流入的反应性管道。
我也在学习反应流,因此,我在下面创建了一个简单的示例,该示例可以为您提供帮助:
Mono<String> first=Mono.just("first");
Mono<String> second=Mono.just("second");
Mono<Tuple2<String, String>> zipped=Mono.zip(first,second);
zipped.map(tuple->someOtherOperation(tuple.getT1(),tuple.getT2()))
.doOnSuccess(s->System.out.println("Success"))
.doOnError(s->System.out.println("Error"))
.subscribe();
我对someOtherOperation
的实现是:
public static Mono<Void> someOtherOperation(String a, String b)
{
System.out.println("Performing Operation "+a+":"+b);
return Mono.empty();
}
因此,在Java应用程序中运行我的代码段将在您的控制台上打印以下内容:
Performing Operation first:second
Success
此外,subscribe
并不是订阅反应流的唯一方法,请查看此文档http://projectreactor.io/docs/core/release/reference/#_simple_ways_to_create_a_flux_or_mono_and_subscribe_to_it