0

在我的 Spring Boot 应用程序中,我有以下入站网关(Java DSL):

@Bean
    public IntegrationFlow upperCaseFlow() {
        return IntegrationFlows
                .from(
                        Http.inboundGateway("/conversions/upperCase")
                        .requestMapping(r -> r.methods(HttpMethod.POST).consumes("text/plain"))
                        .requestPayloadType(String.class)
                        .id("upperCaseGateway")
                )
                .<String>handle((p, h) -> p.toUpperCase())
                .get();
    }

我认为.id ("upperCaseGateway")是为网关设置“id”的部分。

另一方面,我正在尝试以稍微不同的 DSL 样式实现另一个 HTTP 入站网关,如下所示:

@Bean
    public IntegrationFlow httpGetFlow() {
        return IntegrationFlows.from(httpGetGate()).channel("httpGetChannel").handle("personEndpoint", "get").get();
    }

@Bean
    public MessagingGatewaySupport httpGetGate() {
        HttpRequestHandlingMessagingGateway handler = new HttpRequestHandlingMessagingGateway();
        handler.setRequestMapping(createMapping(new HttpMethod[]{HttpMethod.GET}, "/persons/{personId}"));
        handler.setPayloadExpression(parser().parseExpression("#pathVariables.personId"));
        handler.setHeaderMapper(headerMapper());

        return handler;
    }

@Bean
    public HeaderMapper<HttpHeaders> headerMapper() {
        return new DefaultHttpHeaderMapper();
    }

我的问题: 在创建 http 入站网关的第二种方式中,如何为网关设置一个 ID,值为“ getPersonsGateway ”?我看到在第一种风格中,这可以通过简单的.id("upperCaseGateway")调用来实现。

任何指导将不胜感激!

真诚的,巴拉特

4

1 回答 1

2

id只是一个bean名称;对于复合组件(消费者),它是消费者端点 bean 名称,消息处理程序获取<id>.handler.

对于简单的消息驱动组件,例如 http 入站适配器,它只是 bean 名称。所以适当地命名你的bean。

任何一个

@Bean("upperCaseGateway")
public MessagingGatewaySupport httpGetGate() {

或者,简单地说

@Bean
public MessagingGatewaySupport upperCaseGateway() {
于 2019-02-22T21:22:12.790 回答