gpt4 book ai didi

spring-integration - 使用 spring-integration-dsl 的动态 http 入站网关

转载 作者:行者123 更新时间:2023-12-04 07:59:26 26 4
gpt4 key购买 nike

我正在尝试使用 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(入站)时,即 creating a Bean for Integration flow 并在 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 入站网关的解决方案。

最佳答案

这还不可能:https://jira.spring.io/browse/INT-4436 .

不幸的是,没有简单的解决方法让您继续前进,除非您可以只公开一个 REST 端点并根据接受的 HTTP 请求在 IntegrationFlow 内进行路由。

关于spring-integration - 使用 spring-integration-dsl 的动态 http 入站网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49882033/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com