【发布时间】:2018-09-25 12:11:33
【问题描述】:
在 Spring 集成中,消息通道可以这样配置:
<int:channel id="get_send_channel" />
<int:channel id="get_receive_channel">
<int:queue capacity='10' />
</int:channel>
<int-http:outbound-gateway id="get.outbound.gateway"
request-channel="get_send_channel"
url="http://localhost:8080/greeting"
http-method="GET" reply-channel="get_receive_channel"
expected-response-type="java.lang.String">
</int-http:outbound-gateway>
并像这样使用:
@SpringBootApplication
@ImportResource("http-outbound-gateway.xml")
public class HttpApplication {
@Autowired
@Qualifier("get_send_channel")
MessageChannel getSendChannel;
@Autowired
@Qualifier("get_receive_channel")
PollableChannel getReceiveChannel;
public static void main(String[] args) {
SpringApplication.run(HttpApplication.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
Message<?> message = MessageBuilder.withPayload("").build();
getSendChannel.send(message);
System.out.println(getReceiveChannel.receive().getPayload());
};
}
MessageChannel如何动态创建和注册?
以上代码来自this example
我已经试过了
return IntegrationFlows.from(MessageChannels.rendezvous("getSend1"))
.handle(Http.outboundGateway("http://localhost:8080/greeting").httpMethod(HttpMethod.GET))
.channel(MessageChannels.queue("getReceive1")).get();
使用默认轮询器,但有消息:
preReceive on channel 'getSend1'
postReceive on channel 'getSend1', message is null
Received no Message during the poll, returning 'false'
所以配置似乎不正确,消息不是从 URL 中获取的。
【问题讨论】:
-
我将此示例用于另一个有关其他问题的 stackoverflow 问题。我想这可能就是你要找的东西github.com/teplyuska/spring-integration-example
-
是的,可以使用 IntegrationFlows 和 Java DSL,docs.spring.io/spring-integration/docs/current/reference/html/…。是否可以在应用程序启动时从数据库中读取所有配置(URL 等)并配置集成流程?
-
我不明白为什么不这样做。您可能可以将注释 @DependsOn 用于配置集成流的类。然后,您可以依赖要从中读取配置的存储库。
-
您知道如何让 IntegrationFlows 以(向上查看)方式工作吗?它非常接近解决方案stackoverflow.com/questions/40248152/…,但我的实现不起作用。
标签: spring spring-integration spring-integration-dsl message-channel