简体   繁体   English

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

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

The Spring DSL documentation provides a sample project -- café Spring DSL文档提供了一个示例项目-café

I'm unsure of a couple of aspects of how this works. 我不确定这是如何运作的几个方面。 Pasting the relevant excerpts here: (Full source at the above link) 在此处粘贴相关摘录:(以上链接的完整源代码)

@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
}

Reading this example, I'm unclear on a couple of points: 阅读此示例,我不清楚以下几点:

  • The Cafe interface exposes a @Gateway that connects to requestChannel = "orders.input" . Cafe接口公开了一个@Gateway ,它连接到requestChannel = "orders.input" However, this channnel is not defined anywhere. 但是,此通道未在任何地方定义。 How does this work? 这是如何运作的?

  • The DSL snippet does is not wired to consume from any channels, nor does it refer to the Cafe::placeOrder method -- how does this get connected to the orders.input channel to receive the inbound Order ? DSL代码段没有连接到任何通道使用,也没有引用Cafe::placeOrder方法-它如何连接到orders.input通道以接收入站Order

We just published (yesterday) a line-by-line tutorial for the cafe dsl sample which goes into a lot of details about the internals. 我们刚刚(昨天)发布了有关cafédsl示例的逐行教程,其中包含有关内部细节的许多详细信息。

When using the lambda version ( f -> f.split()... ) the framework declares an implicit DirectChannel with the bean name ( "orders" ) + ".input" as its id. 当使用lambda版本( f -> f.split()... )时,框架将声明一个隐式DirectChannel ,其bean名称( "orders" )+ ".input"作为其id。

You can also use return IntegrationFlows.from("myChannel"). ... .get() 您还可以使用return IntegrationFlows.from("myChannel"). ... .get() return IntegrationFlows.from("myChannel"). ... .get() instead of the lambda expression and, again, the framework will auto-generate the channel if not declared as a bean already. return IntegrationFlows.from("myChannel"). ... .get()代替lambda表达式,并且,如果尚未声明为bean,则框架将自动生成通道。

See the InterationFlows javadoc for more information. 有关更多信息,请参见InterationFlows javadoc。

cafe.placeOrder() is invoked in the last line in the for loop in the main method. cafe.placeOrder()main方法的for循环的最后一行中调用。 The framework creates a proxy for the interface that wraps the Order object in a message and sends it to the gateway's request channel. 该框架为接口创建代理,该代理将Order对象包装在消息中,并将其发送到网关的请求通道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM