本文整理匯總了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));
}
示例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...")
);
}
示例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"))));
}
示例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()));
}
}
示例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);
}
}
示例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...")
);
}
示例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);
});
}
示例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();
}
示例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...")
);
}
示例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);
}
示例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;
}
示例13: fromValues
import reactor.core.publisher.Flux; //導入依賴的package包/類
@Test
public void fromValues() {
Flux<String> flux = fooBarFluxFromValues();
StepVerifier.create(flux)
.expectNext("foo", "bar")
.expectComplete()
.verify();
}
示例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));
}
示例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);
}