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


Java Flux.subscribe方法代码示例

本文整理汇总了Java中reactor.core.publisher.Flux.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Java Flux.subscribe方法的具体用法?Java Flux.subscribe怎么用?Java Flux.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reactor.core.publisher.Flux的用法示例。


在下文中一共展示了Flux.subscribe方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestPressure

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@Override
public Mono<NumberProto.Number> requestPressure(Flux<NumberProto.Number> request) {
    if (explicitCancel.get()) {
        // Process a very long sequence
        Disposable subscription = request.subscribe(n -> System.out.println("S: " + n.getNumber(0)));
        return Mono
                .just(protoNum(-1))
                .delayElement(Duration.ofMillis(250))
                // Explicitly cancel by disposing the subscription
                .doOnSuccess(x -> subscription.dispose());
    } else {
        // Process some of a very long sequence and cancel implicitly with a take(10)
        return request.map(req -> req.getNumber(0))
                .doOnNext(System.out::println)
                .take(10)
                .last(-1)
                .map(CancellationPropagationIntegrationTest::protoNum);
    }
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:20,代码来源:CancellationPropagationIntegrationTest.java

示例2: main

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {

		Flux<String> flux = client.get() //
				.uri("/sse/messages") //
				.retrieve() //
				.bodyToFlux(String.class) //
				.doOnNext(System.out::println);

		System.out.println("Subscribing to SSE");
		Disposable subscription = flux.subscribe();

		System.out.println("Press any key to terminate subscription...");
		System.in.read();

		subscription.dispose();
	}
 
开发者ID:mp911de,项目名称:reactive-spring,代码行数:17,代码来源:WorkshopSseClient.java

示例3: importCommits

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
public void importCommits(ProjectEvent projectEvent) throws IOException {
    Project project = projectService.getProject(projectEvent.getProjectId());
    Assert.notNull(project, "Could not find project with the provided id");

    // Get GitHub repository commits
    RepositoryId repositoryId = new RepositoryId(project.getOwner(), project.getName());
    List<RepositoryCommit> repositoryCommits = gitTemplate.commitService().getCommits(repositoryId);

    Flux<Commit> commits;

    commits = Flux.fromStream(repositoryCommits.stream()).map(c -> {
        try {
            log.info("Importing commit: " + repositoryId.getName() + " -> " + c.getSha());
            return gitTemplate.commitService().getCommit(repositoryId, c.getSha());
        } catch (IOException e) {
            throw new RuntimeException("Could not get commit", e);
        }
    }).filter(a -> a.getFiles() != null && a.getFiles().size() < 10)
            .map(a -> new Commit(a.getFiles().stream()
                    .map(f -> new File(f.getFilename())).collect(Collectors.toList()),
                    a.getCommit().getCommitter().getName(),
                    a.getCommit().getCommitter().getDate().getTime()))
            .sort(Comparator.comparing(Commit::getCommitDate));

    commits.subscribe(commit -> saveCommits(project, commit));
}
 
开发者ID:kbastani,项目名称:service-block-samples,代码行数:27,代码来源:CommitProcessor.java

示例4: test3

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@Test
public void test3() {
    Flux<Long> fast = Flux.interval(Duration.ofSeconds(1));
    Flux<Long> slow = Flux.interval(Duration.ofSeconds(3));

    Flux<Long> clock = Flux.merge(
            fast.filter(t -> isFastTime()),
            slow.filter(t -> isSlowTime())
    );

    Flux<LocalDateTime> dateEmitter = Flux.interval(Duration.ofSeconds(1))
            .map(t -> LocalDateTime.now());

    Flux<LocalDateTime> localDateTimeFlux = clock.withLatestFrom(dateEmitter, (tick, date) -> date);

    localDateTimeFlux.subscribe(t -> System.out.println(t.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"))));
}
 
开发者ID:vgrazi,项目名称:reactive-demo,代码行数:18,代码来源:Samples.java

示例5: oneToMany

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
/**
 * Implements a unary -> stream call as {@link Mono} -> {@link Flux}, where the server responds with a
 * stream of messages.
 */
public static <TRequest, TResponse> void oneToMany(
        TRequest request, StreamObserver<TResponse> responseObserver,
        Function<Mono<TRequest>, Flux<TResponse>> delegate) {
    try {
        Mono<TRequest> rxRequest = Mono.just(request);

        Flux<TResponse> rxResponse = Preconditions.checkNotNull(delegate.apply(rxRequest));
        rxResponse.subscribe(new ReactivePublisherBackpressureOnReadyHandler<>(
                (ServerCallStreamObserver<TResponse>) responseObserver));
    } catch (Throwable throwable) {
        responseObserver.onError(prepareError(throwable));
    }
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:18,代码来源:ServerCalls.java

示例6: fluxStreamWithDelay

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@Test
public void fluxStreamWithDelay() throws InterruptedException {
	Flux<String> stubFluxWithNames = Flux.fromIterable(streamOfNames).delayElements(Duration.ofMillis(1000));
	stubFluxWithNames.subscribe(new SystemOutConsumer());
	stubFluxWithNames.subscribe(new WelcomeConsumer());
	Thread.sleep(10000);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Spring-5.0,代码行数:8,代码来源:SpringReactiveTest.java

示例7: printOn

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
private static void printOn(Flux<?> flux) {
    flux.subscribe(System.out::println);
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:4,代码来源:Samples.java

示例8: simpleFluxStream

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@Test
public void simpleFluxStream() {
	Flux<String> stubFluxStream = Flux.just("Jane", "Joe");
	stubFluxStream.subscribe(new SystemOutConsumer());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Spring-5.0,代码行数:6,代码来源:SpringReactiveTest.java


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