Java Code Examples for reactor.core.publisher.Flux#fromIterable()
The following examples show how to use
reactor.core.publisher.Flux#fromIterable() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Spring-5.0-Cookbook File: EmployeeServiceImpl.java License: MIT License | 8 votes |
@Override public Flux<Employee> readEmployeesByAscLastName() { Scheduler subWorker = Schedulers.newSingle("sub-thread"); Scheduler pubWorker = Schedulers.newSingle("pub-thread"); Supplier<Flux<Employee>> deferredTask = ()->{ System.out.println("flux:defer task executor: " + Thread.currentThread().getName()); System.out.println("flux:defer task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal()); return Flux.fromIterable(employeeDaoImpl.getEmployees()); }; Comparator<Employee> descLName = (e1, e2) -> { System.out.println("flux:sort task executor: " + Thread.currentThread().getName()); System.out.println("flux:sort task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal()); return e1.getLastName().compareTo(e2.getLastName()); }; Flux<Employee> deferred = Flux.defer(deferredTask).sort(descLName).subscribeOn(subWorker).publishOn(pubWorker); return deferred; }
Example 2
Source Project: Spring-Boot-Book File: UserController.java License: Apache License 2.0 | 5 votes |
/** * 获取所有用户 * * @return */ @GetMapping("/list") public Flux<User> getAll() { return Flux.fromIterable(users.entrySet().stream() .map(entry -> entry.getValue()) .collect(Collectors.toList())); }
Example 3
Source Project: spring-analysis-note File: ReactiveAdapterRegistryTests.java License: MIT License | 5 votes |
@Test public void publisherToReactivexFlowable() { List<Integer> sequence = Arrays.asList(1, 2, 3); Publisher<Integer> source = Flux.fromIterable(sequence); Object target = getAdapter(io.reactivex.Flowable.class).fromPublisher(source); assertTrue(target instanceof io.reactivex.Flowable); assertEquals(sequence, ((io.reactivex.Flowable<?>) target).toList().blockingGet()); }
Example 4
Source Project: spring-cloud-rsocket File: RoutingTableRoutes.java License: Apache License 2.0 | 5 votes |
@Override public Flux<Route> getRoutes() { // TODO: sorting? // TODO: caching Collection<Route> routeCollection = routes.values(); if (log.isDebugEnabled()) { log.debug("Found routes: " + routeCollection); } return Flux.fromIterable(routeCollection); }
Example 5
Source Project: reactor-core File: FluxSpecTests.java License: Apache License 2.0 | 5 votes |
@Test public void fluxCanBeEnforcedToDispatchValuesHavingDistinctKeys() { // "A Flux can be enforced to dispatch values having distinct keys" // given: "a composable with values 1 to 4 with duplicate keys" Flux<Integer> s = Flux.fromIterable(Arrays.asList(1, 2, 3, 1, 2, 3, 4)); // when: "the values are filtered and result is collected" MonoProcessor<List<Integer>> tap = s.distinct(it -> it % 3) .collectList() .toProcessor(); tap.subscribe(); // then: "collected should be without duplicates" assertThat(tap.block()).containsExactly(1, 2, 3); }
Example 6
Source Project: james-project File: MemoryEventDeadLetters.java License: Apache License 2.0 | 5 votes |
@Override public Flux<InsertionId> failedIds(Group registeredGroup) { Preconditions.checkArgument(registeredGroup != null, REGISTERED_GROUP_CANNOT_BE_NULL); synchronized (deadLetters) { return Flux.fromIterable(ImmutableList.copyOf(deadLetters.row(registeredGroup).keySet())); } }
Example 7
Source Project: spring-cloud-zookeeper File: ZookeeperReactiveDiscoveryClient.java License: Apache License 2.0 | 5 votes |
private Function<String, Publisher<org.apache.curator.x.discovery.ServiceInstance<ZookeeperInstance>>> getInstancesFromZookeeper() { return service -> { try { return Flux.fromIterable(serviceDiscovery.queryForInstances(service)); } catch (Exception e) { logger.error("Error getting instances from zookeeper. Possibly, no service has registered.", e); return Flux.empty(); } }; }
Example 8
Source Project: cloud-spanner-r2dbc File: SpannerStatement.java License: Apache License 2.0 | 5 votes |
@Override public Publisher<? extends Result> execute() { if (this.statementType == StatementType.DDL) { return this.client .executeDdl( this.config.getFullyQualifiedDatabaseName(), Collections.singletonList(this.sql), this.config.getDdlOperationTimeout(), this.config.getDdlOperationPollInterval()) .map(operation -> new SpannerResult(Flux.empty(), Mono.just(0))); } else if (this.statementType == StatementType.DML && !this.ctx.isTransactionPartitionedDml()) { List<ExecuteBatchDmlRequest.Statement> dmlStatements = this.statementBindings.getBindings().stream() .map(struct -> ExecuteBatchDmlRequest.Statement.newBuilder() .setSql(this.sql) .setParams(struct) .putAllParamTypes(this.statementBindings.getTypes()) .build()) .collect(Collectors.toList()); return this.client.executeBatchDml(this.ctx, dmlStatements) .map(partialResultSet -> Math.toIntExact(partialResultSet.getStats().getRowCountExact())) .map(rowCount -> new SpannerResult(Flux.empty(), Mono.just(rowCount))); } Flux<Struct> structFlux = Flux.fromIterable(this.statementBindings.getBindings()); return structFlux.flatMap(this::runStreamingSql); }
Example 9
Source Project: vertx-spring-boot File: Controller.java License: Apache License 2.0 | 4 votes |
/** * Get a flux of previously logged messages. */ @GetMapping(produces = TEXT_EVENT_STREAM_VALUE) public Flux<String> getMessages() { return Flux.fromIterable(log.getMessages()); }
Example 10
Source Project: springboot-learning-example File: CityHandler.java License: Apache License 2.0 | 4 votes |
public Flux<City> findAllCity() { return Flux.fromIterable(cityRepository.findAll()); }
Example 11
Source Project: Spring-5.0-Cookbook File: LoginHandler.java License: MIT License | 4 votes |
public Mono<ServerResponse> loginDetailsList(ServerRequest req) { Flux<LoginDetails> flux = Flux.fromIterable(logindetailsServiceImpl.findAllLogindetails()); return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(flux, LoginDetails.class); }
Example 12
Source Project: vertx-spring-boot File: Controller.java License: Apache License 2.0 | 4 votes |
/** * Get a flux of previously logged messages. */ @GetMapping(produces = TEXT_EVENT_STREAM_VALUE) public Flux<String> getMessages() { return Flux.fromIterable(log.getMessages()); }
Example 13
Source Project: spring-reactive-sample File: PostRepository.java License: GNU General Public License v3.0 | 4 votes |
Flux<Post> findAll() { return Flux.fromIterable(data.values()); }
Example 14
Source Project: jetlinks-community File: LocalClientSession.java License: Apache License 2.0 | 4 votes |
@Override public Flux<Subscription> getSubscriptions() { return Flux.fromIterable(subscriptions.values()); }
Example 15
Source Project: Spring-5.0-Cookbook File: LoginReactController.java License: MIT License | 4 votes |
@GetMapping("/fluxJpaUsers") public Flux<UserDetails> exposeJpaUsers() { return Flux.fromIterable(userdetailsServiceImpl.findAllUserdetails()); }
Example 16
Source Project: james-project File: MemoryEventDeadLetters.java License: Apache License 2.0 | 4 votes |
@Override public Flux<Group> groupsWithFailedEvents() { synchronized (deadLetters) { return Flux.fromIterable(ImmutableList.copyOf(deadLetters.rowKeySet())); } }
Example 17
Source Project: spring-5-examples File: MovieService.java License: MIT License | 4 votes |
public Flux<Movie> getAll() { return Flux.fromIterable(repository.findAll()); // return repository.findAll(); }
Example 18
Source Project: titus-control-plane File: JooqJobActivityPublisherStoreTest.java License: Apache License 2.0 | 4 votes |
private Flux<BatchJobTask> observeTasks(int count) { return Flux.fromIterable(batchTasksGenerator.batch(count).getValue()); }
Example 19
Source Project: spring-cloud-function File: AzureSpringBootRequestHandler.java License: Apache License 2.0 | 4 votes |
protected Flux<?> extract(Object input) { if (!isSingleInput(this.getFunction(), input)) { return Flux.fromIterable((Iterable<?>) input); } return Flux.just(input); }
Example 20
Source Project: Spring-5.0-Cookbook File: RestServiceController.java License: MIT License | 4 votes |
@GetMapping("/fluxJpaEmps") public Flux<Employee> exposeJpaEmps() { return Flux.fromIterable(employeeServiceImpl.findAllEmps()); }