Wire tap as async channel?

266 Views Asked by At

Is it right to use "wiretap" as a second line logic channel?

Or I should use another methods? I not found anything appropriate (pubSubChannel?)

For example:

    @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");
}
1

There are 1 best solutions below

2
Artem Bilan On

If you want that wireTap("logicHard.input") to be async, you need to start your logicHard flow from the ExecutorChannel with respective Executor injected. Or QueueChannel. See IntegrationFlows factory and its:

/**
 * 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) {

See that MessageChannels factory.

On the other hand if you talk about a parallel logic, then it is indeed better to take a look into the PublishSubscribeChannel with an Executor option. Your logicHard flow logic might remain. Only what you need to have a global PublishSubscribeChannel bean and start that flow from this channel. In the main flow instead of .wireTap("logicHard.input") you need to use a plain channel(myPublishSubscribeChannel()) to refer to the same bean.