在尝试对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");
}
}
}
我以这种方式构造它,以便可以:
问题:
答案 0 :(得分:0)
@Gateway
注释不起作用。我认为您的方法没有问题;您将无法重复使用出站网关(如果声明为@Bean
,则可以使用)。这是因为任何产生回复的MessageHandler
只能有一个输出通道。
@MessagingGateway
用于创建GatewayProxyFactoryBean
-用于从旧版Java代码连接到集成流。