當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。