我正在尝试使用Java DSL作为下面提供的代码为HTTP入站网关创建和注册运行时集成流程
@Autowired
private IntegrationFlowContext flowContext;
public static void main(String[] args) {
SpringApplication.run(RestClientDemoApplication.class, args);
}
@ServiceActivator(inputChannel="httpRequest")
public String upCase(String in) {
System.out.println("message received" + in);
return in.toUpperCase();
}
@Bean
public MessageChannel directChannel(){
return MessageChannels.direct().get();
}
/*@Bean
public IntegrationFlow inbound() {
return IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.POST))
.requestPayloadType(String.class).replyChannel(directChannel()))
.channel("httpRequest")
.get();
}
*/
@Override
public void run(String... args) throws Exception {
IntegrationFlow flow;
IntegrationFlowRegistration theFlow;
flow = IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.POST))
.requestPayloadType(String.class).replyChannel(directChannel()))
.channel("httpRequest")
.get();
theFlow = this.flowContext.registration(flow).register();
}
在这种情况下,我的请求url(" / foo")没有映射到服务器,就像我从HTTP客户端发送消息,然后在服务器端没有收到消息。 但是当我取消注释上面的bean(入站),即创建Bean for Integration流程并在run方法中注释流创建和注册代码(删除运行时集成流程代码) 如下所示正常工作:
@Autowired
private IntegrationFlowContext flowContext;
public static void main(String[] args) {
SpringApplication.run(RestClientDemoApplication.class, args);
}
@ServiceActivator(inputChannel="httpRequest")
public String upCase(String in) {
System.out.println("message received" + in);
return in.toUpperCase();
}
@Bean
public MessageChannel directChannel(){
return MessageChannels.direct().get();
}
@Bean
public IntegrationFlow inbound() {
return IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.POST))
.requestPayloadType(String.class).replyChannel(directChannel()))
.channel("httpRequest")
.get();
}
@Override
public void run(String... args) throws Exception {
/*IntegrationFlow flow;
IntegrationFlowRegistration theFlow;
flow = IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.POST))
.requestPayloadType(String.class).replyChannel(directChannel()))
.channel("httpRequest")
.get();
theFlow = this.flowContext.registration(flow).register();*/
}
我的HTTP出站网关代码如下
flow = IntegrationFlows.from(directChannel()).handle(Http.outboundGateway("https://localhost:8448/foo")
.httpMethod(HttpMethod.POST).expectedResponseType(String.class)).channel("httpReply").get();
theFlow = this.flowContext.registration(flow).register();
如果这种方法不合适,请帮我解决上述问题或提供在运行时创建Http入站网关的解决方案。
答案 0 :(得分:0)
这还不可能:https://jira.spring.io/browse/INT-4436。
不幸的是,除非您只公开一个REST端点并根据接受的HTTP请求在IntegrationFlow
内部进行路由,否则没有简单的解决方法可供您继续使用。