簡體   English   中英

Spring Integration DSL Cafe示例-通道如何布線?

[英]Spring Integration DSL Cafe example — how are channels wired?

Spring DSL文檔提供了一個示例項目-café

我不確定這是如何運作的幾個方面。 在此處粘貼相關摘錄:(以上鏈接的完整源代碼)

@Configuration
@EnableAutoConfiguration
@IntegrationComponentScan
public class Application {

public static void main(String[] args) throws InterruptedException {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);

    Cafe cafe = ctx.getBean(Cafe.class);
    for (int i = 1; i <= 100; i++) {
        Order order = new Order(i);
        order.addItem(DrinkType.LATTE, 2, false);
        order.addItem(DrinkType.MOCHA, 3, true);
        cafe.placeOrder(order);
    }

    Thread.sleep(60000);

    ctx.close();
}

@MessagingGateway
public interface Cafe {

    @Gateway(requestChannel = "orders.input")
    void placeOrder(Order order);

}


@Bean
public IntegrationFlow orders() {
    return f -> f
            .split(Order.class, Order::getItems)
            .channel(c -> c.executor(Executors.newCachedThreadPool()))
            // SNIP
}

閱讀此示例,我不清楚以下幾點:

  • Cafe接口公開了一個@Gateway ,它連接到requestChannel = "orders.input" 但是,此通道未在任何地方定義。 這是如何運作的?

  • DSL代碼段沒有連接到任何通道使用,也沒有引用Cafe::placeOrder方法-它如何連接到orders.input通道以接收入站Order

我們剛剛(昨天)發布了有關cafédsl示例的逐行教程,其中包含有關內部細節的許多詳細信息。

當使用lambda版本( f -> f.split()... )時,框架將聲明一個隱式DirectChannel ,其bean名稱( "orders" )+ ".input"作為其id。

您還可以使用return IntegrationFlows.from("myChannel"). ... .get() return IntegrationFlows.from("myChannel"). ... .get()代替lambda表達式,並且,如果尚未聲明為bean,則框架將自動生成通道。

有關更多信息,請參見InterationFlows javadoc。

cafe.placeOrder()main方法的for循環的最后一行中調用。 該框架為接口創建代理,該代理將Order對象包裝在消息中,並將其發送到網關的請求通道。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM