当前位置: 首页>>代码示例>>Java>>正文


Java Mono.subscribe方法代码示例

本文整理汇总了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);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:27,代码来源:EmployeeHotStreamServiceImpl.java

示例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);
    }
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:17,代码来源:ClientCalls.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Spring-5.0,代码行数:10,代码来源:SpringReactiveTest.java


注:本文中的reactor.core.publisher.Mono.subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。