本文整理汇总了Java中reactor.core.publisher.Flux.fromStream方法的典型用法代码示例。如果您正苦于以下问题:Java Flux.fromStream方法的具体用法?Java Flux.fromStream怎么用?Java Flux.fromStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.publisher.Flux
的用法示例。
在下文中一共展示了Flux.fromStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: incorporate
import reactor.core.publisher.Flux; //导入方法依赖的package包/类
/**
* Incorporates a new {@link CartEvent} and update the shopping cart
* @param cartEvent 是将要改变购物车状态的{@link CartEvent}
* @return 在应用了新的 {@link CartEvent} 后返回 {@link ShoppingCart} 的状态
*/
public ShoppingCart incorporate(CartEvent cartEvent) {
Flux<CartEventType> validCartEventTypes =
Flux.fromStream(Stream.of(CartEventType.ADD_ITEM, CartEventType.REMOVE_ITEM));
// CartEvent类型必须是 ADD_ITEM or REMOVE_ITEM
if(validCartEventTypes.exists(cartEventType ->
cartEvent.getCartEventType().equals(cartEventType)).get()) {
// 根据事件类型更新购物车每个产品的数量的聚合
productMap.put(cartEvent.getProductId(),
productMap.getOrDefault(cartEvent.getProductId(), 0) +
(cartEvent.getQuantity() * (cartEvent.getCartEventType()
.equals(CartEventType.ADD_ITEM) ? 1 : -1))
);
}
// Return the updated state of the aggregate to the reactive stream's reduce method
return this;
}
示例2: 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();
}
示例3: data4
import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@Test
public void data4() {
// tag::4[]
Stream<String> items = Arrays.asList("alpha", "bravo", "charlie").stream();
Flux.fromStream(items);
// end::4[]
}
示例4: aggregateCartEvents
import reactor.core.publisher.Flux; //导入方法依赖的package包/类
/**
* 聚合(Aggregate)一个用户的cart events,返回一个 {@link ShoppingCart}
* @param user 获取购物车的用户
* @param catalog 用于生成购物车的目录
* @return 一个表示用户购物车聚合状态的购物车
* @throws Exception 如果在购物车中的一个产品不在目录里面,则抛出异常
*/
public ShoppingCart aggregateCartEvents(User user, Catalog catalog) throws Exception {
Flux<CartEvent> cartEvents = Flux.fromStream(cartEventRepository.getCartEventStreamByUserId(user.getId()));
// 聚合购物车的状态
ShoppingCart shoppingCart = cartEvents.takeWhile(cartEvent -> !ShoppingCart.isTerminal(cartEvent.getCartEventType()))
.reduceWith(() -> new ShoppingCart(catalog), ShoppingCart::incorporate)
.get();
shoppingCart.getCartItems();
return shoppingCart;
}
示例5: stream
import reactor.core.publisher.Flux; //导入方法依赖的package包/类
public Mono<ServerResponse> stream(ServerRequest req) {
Stream<String> streamData = Stream.of("i", "love", "reactive", "programming").sorted()
.map((str) -> str.toUpperCase() + " ");
Flux<String> flux = Flux.fromStream(streamData);
return ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(flux, String.class);
}
示例6: getStocksByMonitoredStockCodes
import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@GetMapping("/stocks")
public Flux<Stock> getStocksByMonitoredStockCodes() {
return Flux.fromStream(getStockService().getRealtimeStocksSamples(getStockService().getMonitoredStockCodes()));
}
示例7: verifyInfiniteStreamEmission
import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@Test
public void verifyInfiniteStreamEmission() {
Stream<Double> stream = Stream.generate(Math::random);
Flux<Double> flux = Flux.fromStream(stream);
StepVerifier.create(flux).expectNextCount(5).thenCancel().verify();
}