Java Code Examples for reactor.core.publisher.Flux#fromIterable()

The following examples show how to use reactor.core.publisher.Flux#fromIterable() . 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 File: EmployeeServiceImpl.java    From Spring-5.0-Cookbook with MIT License 8 votes vote down vote up
@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 File: ReactiveAdapterRegistryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 3
Source File: RoutingTableRoutes.java    From spring-cloud-rsocket with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: SpannerStatement.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: FluxSpecTests.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@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 File: MemoryEventDeadLetters.java    From james-project with Apache License 2.0 5 votes vote down vote up
@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 File: UserController.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
/**
 * 获取所有用户
 *
 * @return
 */
@GetMapping("/list")
public Flux<User> getAll() {
    return Flux.fromIterable(users.entrySet().stream()
            .map(entry -> entry.getValue())
            .collect(Collectors.toList()));
}
 
Example 8
Source File: ZookeeperReactiveDiscoveryClient.java    From spring-cloud-zookeeper with Apache License 2.0 5 votes vote down vote up
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 9
Source File: PostRepository.java    From spring-reactive-sample with GNU General Public License v3.0 4 votes vote down vote up
Flux<Post> findAll() {
    return Flux.fromIterable(data.values());
}
 
Example 10
Source File: RestServiceController.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@GetMapping("/fluxJpaEmps")
public Flux<Employee> exposeJpaEmps() {
	return Flux.fromIterable(employeeServiceImpl.findAllEmps());
}
 
Example 11
Source File: AzureSpringBootRequestHandler.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
protected Flux<?> extract(Object input) {
	if (!isSingleInput(this.getFunction(), input)) {
		return Flux.fromIterable((Iterable<?>) input);
	}
	return Flux.just(input);
}
 
Example 12
Source File: JooqJobActivityPublisherStoreTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private Flux<BatchJobTask> observeTasks(int count) {
    return Flux.fromIterable(batchTasksGenerator.batch(count).getValue());
}
 
Example 13
Source File: MovieService.java    From spring-5-examples with MIT License 4 votes vote down vote up
public Flux<Movie> getAll() {
    return Flux.fromIterable(repository.findAll());
//    return repository.findAll();
  }
 
Example 14
Source File: MemoryEventDeadLetters.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public Flux<Group> groupsWithFailedEvents() {
    synchronized (deadLetters) {
        return Flux.fromIterable(ImmutableList.copyOf(deadLetters.rowKeySet()));
    }
}
 
Example 15
Source File: LoginReactController.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@GetMapping("/fluxJpaUsers")
public Flux<UserDetails> exposeJpaUsers() {
	return Flux.fromIterable(userdetailsServiceImpl.findAllUserdetails());
}
 
Example 16
Source File: LocalClientSession.java    From jetlinks-community with Apache License 2.0 4 votes vote down vote up
@Override
public Flux<Subscription> getSubscriptions() {
    return Flux.fromIterable(subscriptions.values());
}
 
Example 17
Source File: Controller.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
/**
 * Get a flux of previously logged messages.
 */
@GetMapping(produces = TEXT_EVENT_STREAM_VALUE)
public Flux<String> getMessages() {
    return Flux.fromIterable(log.getMessages());
}
 
Example 18
Source File: LoginHandler.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
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 19
Source File: CityHandler.java    From springboot-learning-example with Apache License 2.0 4 votes vote down vote up
public Flux<City> findAllCity() {
    return Flux.fromIterable(cityRepository.findAll());
}
 
Example 20
Source File: Controller.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
/**
 * Get a flux of previously logged messages.
 */
@GetMapping(produces = TEXT_EVENT_STREAM_VALUE)
public Flux<String> getMessages() {
    return Flux.fromIterable(log.getMessages());
}