首页 > 解决方案 > 线接头作为异步通道?

问题描述

使用“窃听”作为二线逻辑通道是否正确?

或者我应该使用其他方法?我没有找到任何合适的东西(pubSubChannel?)

例如:

    @Bean
HttpRequestHandlingMessagingGateway srvPutVers() {
    return Http.inboundGateway("/srvPutVers")
            .requestChannel("callLogicAndReply.input")
            .requestPayloadType(SomeRq.class)
            .get();
}

@Bean
IntegrationFlow callLogicAndReply() {
    return f -> f
            .wireTap("logicHard.input")
            .transform(p -> "{\"status\": \"Ok\"}");
}

@Bean
IntegrationFlow logicHard() {
    return f -> f
            .log("hard logic");
}

标签: spring-integrationspring-integration-dslspring-integration-http

解决方案


如果您希望它wireTap("logicHard.input")是异步的,您需要从相应的注入开始您的logicHard流程。或。查看工厂及其:ExecutorChannelExecutorQueueChannelIntegrationFlows

/**
 * Populate the {@link MessageChannel} object to the
 * {@link IntegrationFlowBuilder} chain using the fluent API from {@link MessageChannelSpec}.
 * The {@link org.springframework.integration.dsl.IntegrationFlow} {@code inputChannel}.
 * @param messageChannelSpec the MessageChannelSpec to populate {@link MessageChannel} instance.
 * @return new {@link IntegrationFlowBuilder}.
 * @see org.springframework.integration.dsl.MessageChannels
 */
public static IntegrationFlowBuilder from(MessageChannelSpec<?, ?> messageChannelSpec) {

看那个MessageChannels工厂。

另一方面,如果您谈论并行逻辑,那么最好看看PublishSubscribeChannelwith an Executoroption。您的logicHard流程逻辑可能会保留。只有您需要拥有一个全局PublishSubscribeChannelbean 并从此通道开始该流程。在主要流程中,.wireTap("logicHard.input")您需要使用普通channel(myPublishSubscribeChannel())的来引用同一个 bean。


推荐阅读