繁体   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