【问题标题】:Modularizing Spring Integration Gateways模块化 Spring 集成网关
【发布时间】:2019-03-01 08:11:12
【问题描述】:

在尝试模块化 Spring Integration 流时,我开始使用一种模式,我将入站和出站网关放在单独的类中,然后在需要的地方导入它们以构建流。例如,这是一个显示粗略方法的最小集成测试:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { SampleIntegrationFlowTest.class })
@SpringIntegrationTest
@EnableIntegration
public class SampleIntegrationFlowTest {

    @Autowired
    private InboundGateways inboundGateways;

    @Autowired
    private OutboundGateways outboundGateways;

    @Test
    public void testFlow1() {
        StandardIntegrationFlow flow = IntegrationFlows
            .from(inboundGateways.createAccount())
            .transform(new JsonToXmlTransformer())
            .handle(outboundGateways.soapAccount())
            .transform(new XmlToJsonTransformer())
            .get();

        flow.start();
    }

    @Test
    public void testFlow2() {
        StandardIntegrationFlow flow = IntegrationFlows
            .from(inboundGateways.searchAccount())
            .transform(new JsonToXmlTransformer())
            .handle(outboundGateways.soapAccount())
            .transform(new XmlToJsonTransformer())
            .get();

        flow.start();
    }

    @Configuration
    static class InboundGateways {

        @Gateway
        public MessagingGatewaySupport createAccount() {
            return WebFlux.inboundGateway("/accounts")
                .requestMapping(mapping -> mapping
                    .consumes("application/json")
                    .produces("application/json")
                    .methods(HttpMethod.POST))
                .get();
        }

        @Gateway
        public MessagingGatewaySupport searchAccount() {
            return WebFlux.inboundGateway("/accounts")
                .requestMapping(mapping -> mapping
                    .produces("application/json")
                    .methods(HttpMethod.GET))
                .headerExpression("name", "#requestParams.name")
                .get();
        }

    }

    @Configuration
    static class OutboundGateways {

        @Gateway
        public MessageHandler soapAccount() {
            return new SimpleWebServiceOutboundGateway("http://example.com/accounts");
        }

    }
}

我以这种方式构建它以便我可以:

  1. 将入站网关组合在一起,以便我可以从 Swagger 合同生成 InboundGateways 类。
  2. 能够重用来自多个流的出站网关(多个入站休息端点路由到同一个出站soap端点)。

问题:

  1. 我的结构方式有什么缺点吗?鉴于上述目标,有什么方法可以改进它?
  2. 是否有机会将入站网关“建模”为使用@MessagingGateway/@Gateway 注释的接口,以便我可以像普通 pojo 一样与它们交互?这在集成到现有代码或通过集成测试时可能很有用。如果有办法,我不知道如何做类似 Webflux.inboundGateway(

【问题讨论】:

    标签: spring-integration spring-integration-dsl


    【解决方案1】:
    1. @Gateway 注释没有任何作用。

    我认为您的方法没有问题;您不能重复使用出站网关(如果声明为@Bean - 您可以使用它)。这是因为任何产生回复的MessageHandler 只能有一个输出通道。

    1. 不; @MessagingGateway 用于创建 GatewayProxyFactoryBean - 用于从旧版 Java 代码连接到集成流。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-21
      • 2018-06-15
      • 2014-07-24
      • 2014-06-08
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多