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


Java Flux.fromStream方法代码示例

本文整理汇总了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;
}
 
开发者ID:chaokunyang,项目名称:microservices-event-sourcing,代码行数:24,代码来源:ShoppingCart.java

示例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();
}
 
开发者ID:chaokunyang,项目名称:microservices-event-sourcing,代码行数:21,代码来源:OrderServiceV1.java

示例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[]
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:8,代码来源:ExampleTests.java

示例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;
}
 
开发者ID:chaokunyang,项目名称:microservices-event-sourcing,代码行数:19,代码来源:ShoppingCartServiceV1.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:7,代码来源:DataHandler.java

示例6: getStocksByMonitoredStockCodes

import reactor.core.publisher.Flux; //导入方法依赖的package包/类
@GetMapping("/stocks")
public Flux<Stock> getStocksByMonitoredStockCodes() {
    return Flux.fromStream(getStockService().getRealtimeStocksSamples(getStockService().getMonitoredStockCodes()));
}
 
开发者ID:mumukiller,项目名称:stock-patterns-recognition,代码行数:5,代码来源:SamplesController.java

示例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();
}
 
开发者ID:mp911de,项目名称:reactive-spring,代码行数:10,代码来源:Step2Flux.java


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