本文整理汇总了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);
}
}
示例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();
}
示例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));
}
示例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"))));
}
示例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));
}
}
示例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);
}
示例7: printOn
import reactor.core.publisher.Flux; //导入方法依赖的package包/类
private static void printOn(Flux<?> flux) {
flux.subscribe(System.out::println);
}
示例8: simpleFluxStream
import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@Test
public void simpleFluxStream() {
Flux<String> stubFluxStream = Flux.just("Jane", "Joe");
stubFluxStream.subscribe(new SystemOutConsumer());
}