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


Java Flux类代码示例

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


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

示例1: testWithString

import reactor.core.publisher.Flux; //导入依赖的package包/类
@Ignore
@Test
public void testWithString() throws Exception {
    KafkaComponent kafka = createComponent();
    
    Mono<List<String>> receive = Flux.from(kafka.from(TOPIC2, String.class))
        .take(2)
        .collectList();
    
    Subscriber<ProducerRecord> toTopic = kafka.to(TOPIC2, ProducerRecord.class);
    Flux.just(new ProducerRecord<String, String>(TOPIC2, "1", "test"),
              new ProducerRecord<String, String>(TOPIC2, "1", "test2"))
        .subscribe(toTopic);

    List<String> received = receive.block(Duration.ofSeconds(10));
    Assert.assertEquals(2, received.size());
    Assert.assertEquals("test", received.get(0));
    Assert.assertEquals("test2", received.get(1));
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:20,代码来源:TestKafka.java

示例2: init

import reactor.core.publisher.Flux; //导入依赖的package包/类
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
    log.info("start data initialization  ...");
    this.posts
        .deleteAll()
        .thenMany(
            Flux
                .just("Post one", "Post two")
                .flatMap(
                    title -> this.posts.save(Post.builder().title(title).content("content of " + title).build())
                )
        )
        .log()
        .subscribe(
            null,
            null,
            () -> log.info("done initialization...")
        );

}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:21,代码来源:DataInitializer.java

示例3: 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

示例4: requestStream

import reactor.core.publisher.Flux; //导入依赖的package包/类
@Override
public Flux<Payload> requestStream(Payload payload) {
	JsonNode metadata = readConnectionMetadata(payload.getMetadataUtf8());
	try {
		MethodHandler handler = handlerFor(metadata);
		Converter converter = converterFor(MimeType.valueOf(metadata.get("MIME_TYPE").textValue()));
		Object converted = converter.read(ServiceUtils.toByteArray(payload.getData()), getActualType(handler.getInfo().getParameterType()));
		Flux result = (Flux)handler.invoke(handler.getInfo().buildInvocationArguments(converted, null));
		return result.map(o ->
			new PayloadImpl(converter.write(o))
		);

	} catch (Exception e){
		return Flux.error(new ApplicationException("No path found for " + metadata.get("PATH").asText()));
	}
}
 
开发者ID:viniciusccarvalho,项目名称:spring-cloud-sockets,代码行数:17,代码来源:DispatcherHandler.java

示例5: requestStream

import reactor.core.publisher.Flux; //导入依赖的package包/类
@Override
public Flux<Payload> requestStream(Payload payload) {
  try {
    ByteBuf metadata = Unpooled.wrappedBuffer(payload.getMetadata());
    int namespaceId = ProteusMetadata.namespaceId(metadata);
    int serviceId = ProteusMetadata.serviceId(metadata);

    ProteusService proteusService = getService(namespaceId, serviceId);

    if (proteusService == null) {
      return Flux.error(new ServiceNotFound(namespaceId, serviceId));
    }

    return proteusService.requestStream(payload);

  } catch (Throwable t) {
    return Flux.error(t);
  }
}
 
开发者ID:netifi,项目名称:proteus-java,代码行数:20,代码来源:RequestHandlingRSocket.java

示例6: init

import reactor.core.publisher.Flux; //导入依赖的package包/类
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
    log.info("start data initialization  ...");
    this.posts
        .deleteAll()
        .thenMany(

            Flux
                .range(1, 1000)
                .flatMap(
                    num -> this.posts.save(Post.builder().title("Title" + num).content("content of " + "Title" + num).build())
                )
        )
        .log()
        .subscribe(
            null,
            null,
            () -> log.info("done initialization...")
        );

}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:22,代码来源:DataInitializer.java

示例7: requestChannel

import reactor.core.publisher.Flux; //导入依赖的package包/类
@Override
public Flux<Payload> requestChannel(Publisher<Payload> payloads) {
  return new SwitchTransform<>(payloads, (payload, flux) -> {
    ByteBuf metadata = Unpooled.wrappedBuffer(payload.getMetadata());
    int namespaceId = ProteusMetadata.namespaceId(metadata);
    int serviceId = ProteusMetadata.serviceId(metadata);

    ProteusService proteusService = getService(namespaceId, serviceId);

    if (proteusService == null) {
      return Flux.error(new ServiceNotFound(namespaceId, serviceId));
    }

    return proteusService.requestChannel(payload, flux);
  });
}
 
开发者ID:netifi,项目名称:proteus-java,代码行数:17,代码来源:RequestHandlingRSocket.java

示例8: getOrder

import reactor.core.publisher.Flux; //导入依赖的package包/类
public Order getOrder(String orderId, Boolean validate) {
    // 获取订单
    Order order = orderRepositroy.findOne(orderId);

    if(validate) {
        // 验证事件对应的订单的账户号(account number)属于用户
        try {
            validateAccountNumber(order.getAccountNumber());
        } catch (Exception e) {
            return null;
        }
    }

    Flux<OrderEvent> orderEvents = Flux.fromStream(orderEventRepository.findOrderEventsByOrderId(orderId));

    // 聚合订单状态
    return orderEvents.takeWhile(orderEvent -> orderEvent.getType() != OrderEventType.DELIVERED)
            .reduceWith(() -> order, Order::incorporate)
            .get();
}
 
开发者ID:chaokunyang,项目名称:microservices-event-sourcing,代码行数:21,代码来源:OrderServiceV1.java

示例9: initPosts

import reactor.core.publisher.Flux; //导入依赖的package包/类
private void initPosts() {
    log.info("start data initialization  ...");
    this.posts
        .deleteAll()
        .thenMany(
            Flux
                .just("Post one", "Post two")
                .flatMap(
                    title -> this.posts.save(Post.builder().title(title).content("content of " + title).build())
                )
        )
        .log()
        .subscribe(
            null,
            null,
            () -> log.info("done initialization...")
        );
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:19,代码来源:DataInitializer.java

示例10: getAllBooks

import reactor.core.publisher.Flux; //导入依赖的package包/类
@GetMapping("/books")
public Flux<List<Book>> getAllBooks() {

	ArrayList<Book> books=new ArrayList<Book>();
	books.add(new Book("Spring 5.0",1234l,"Packt Pub Publication",500,"Learn Spring", "T.M.Jog"));
	books.add(new Book("Learn Modular Java",1234l,"Packt Pub Publication",500,"Learn java", "Author1"));
	return Flux.just(books);
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:9,代码来源:MyBookController.java

示例11: decide

import reactor.core.publisher.Flux; //导入依赖的package包/类
public Mono<Boolean> decide(Authentication authentication, Object object, Flux<ConfigAttribute> configAttributes) {
	return Mono
		.just(Tuples.of(authentication, object, configAttributes))
		.publishOn(Schedulers.elastic())
		.filter((Tuple3<Authentication, Object, Flux<ConfigAttribute>> t) -> {
			Authentication auth = t.getT1();
			return auth != null && auth.isAuthenticated();
		})
		.then((Function<Tuple3<Authentication, Object, Flux<ConfigAttribute>>, Mono<Boolean>>) t -> {
			List<ConfigAttribute> attrs = new ArrayList<>();
			t.getT3().toIterable().forEach(attrs::add);

			try {
				accessDecisionManager.decide(t.getT1(), t.getT2(), attrs);
				return Mono.just(true);
			} catch(AccessDeniedException fail) {
				return Mono.just(false);
			}
		});
}
 
开发者ID:guilhebl,项目名称:item-shop-reactive-backend,代码行数:21,代码来源:ReactiveAccessDecisionManagerAdapter.java

示例12: createPublisher

import reactor.core.publisher.Flux; //导入依赖的package包/类
@Override
public Publisher<Message> createPublisher(long elements) {
    ReactorTckGrpc.ReactorTckStub stub = ReactorTckGrpc.newReactorStub(channel);
    Flux<Message> request = Flux.range(0, (int)elements).map(this::toMessage);
    Publisher<Message> publisher = stub.manyToMany(request);

    return publisher;
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:9,代码来源:ReactorGrpcPublisherManyToManyVerificationTest.java

示例13: fromValues

import reactor.core.publisher.Flux; //导入依赖的package包/类
@Test
public void fromValues() {
    Flux<String> flux = fooBarFluxFromValues();
    StepVerifier.create(flux)
                .expectNext("foo", "bar")
                .expectComplete()
                .verify();
}
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:9,代码来源:FluxSampleTest.java

示例14: zipReplacedDistinctSortedLettersWithRange

import reactor.core.publisher.Flux; //导入依赖的package包/类
private static void zipReplacedDistinctSortedLettersWithRange() {
    printOn(Flux
            .fromArray(STRINGS)
            .flatMap(w -> Flux.fromArray(w.split("")))
            .concatWith(Mono.just("s"))
            .distinct()
            .sort()
            .zipWith(Flux.range(1, Integer.MAX_VALUE), Samples::formatZipped));
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:10,代码来源:Samples.java

示例15: test2

import reactor.core.publisher.Flux; //导入依赖的package包/类
@Test
public void test2() {

    List<String> words = Arrays.asList(
            "the",
            "quick",
            "brown",
            "fox",
            "jumped",
            "over",
            "the",
            "lazy",
            "dog"
    );
    Flux<Integer> range = Flux.range(1, Integer.MAX_VALUE);
    Flux.fromIterable(words)
            .flatMap(word -> Flux.fromArray(word.split("")))
            .sort()
            .distinct()
            .zipWith(range, (word, line) -> line + ":" + word)
            .subscribe(System.out::println);

}
 
开发者ID:vgrazi,项目名称:reactive-demo,代码行数:24,代码来源:ReactorTests.java


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