本文整理汇总了Java中reactor.core.publisher.Mono.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Java Mono.subscribe方法的具体用法?Java Mono.subscribe怎么用?Java Mono.subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.publisher.Mono
的用法示例。
在下文中一共展示了Mono.subscribe方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: monoProcessorGetEmployee
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public void monoProcessorGetEmployee(Integer id) {
MonoProcessor<Integer> future = MonoProcessor.create();
Consumer<Integer> checkEmp = (rowId) ->{
if(employeeDaoImpl.getEmployee(rowId) == null){
System.out.println("Employee with id: " + rowId + " does not exists.");
}else{
System.out.println("Employee with id: " + rowId + " exists.");
}
};
Mono<Integer> engine = future
.doOnNext(checkEmp)
.doOnSuccess(emp -> {
System.out.println("Employee's age is " + employeeDaoImpl.getEmployee(emp).getAge());
System.out.println("Employee's dept is: " + employeeDaoImpl.getEmployee(emp).getDeptId());
})
.doOnTerminate((sup, ex) -> System.out.println("Transaction terminated with error: " +ex.getMessage()))
.doOnError(ex -> System.out.println("Error: " + ex.getMessage()));
engine.subscribe(System.out::println);
future.onNext(id);
int valStream = future.block();
System.out.println("Employee's ID again is: " + valStream);
}
示例2: oneToMany
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
/**
* Implements a unary -> stream call as {@link Mono} -> {@link Flux}, where the server responds with a
* stream of messages.
*/
public static <TRequest, TResponse> Flux<TResponse> oneToMany(
Mono<TRequest> rxRequest,
BiConsumer<TRequest, StreamObserver<TResponse>> delegate) {
try {
ReactorConsumerStreamObserver<TRequest, TResponse> consumerStreamObserver = new ReactorConsumerStreamObserver<>();
rxRequest.subscribe(request -> delegate.accept(request, consumerStreamObserver));
return ((Flux<TResponse>) consumerStreamObserver.getRxConsumer())
.transform(Operators.lift(new SubscribeOnlyOnceLifter<TResponse>()));
} catch (Throwable throwable) {
return Flux.error(throwable);
}
}
示例3: monoExample
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Test
public void monoExample() throws InterruptedException {
Mono<String> stubMonoWithADelay = Mono.just("Ranga").delayElement(Duration.ofSeconds(5));
stubMonoWithADelay.subscribe(new SystemOutConsumer());
//stubMonoWithADelay.subscribe(new WelcomeConsumer());
Thread.sleep(10000);
}