MessageChannelSpec.wireTap()

Spring Integration には、.wireTap() fluent API MessageChannelSpec ビルダーが含まれています。次の例は、wireTap メソッドを使用して入力を記録する方法を示しています。

@Bean
public QueueChannelSpec myChannel() {
    return MessageChannels.queue()
            .wireTap("loggingFlow.input");
}

@Bean
public IntegrationFlow loggingFlow() {
    return f -> f.log();
}

MessageChannel が InterceptableChannel のインスタンスである場合、log()wireTap()intercept() 演算子が現在の MessageChannel に適用されます。それ以外の場合は、現在構成されているエンドポイントのフローに中間 DirectChannel が挿入されます。次の例では、DirectChannel が InterceptableChannel を実装しているため、WireTap インターセプターが myChannel に直接追加されます。

@Bean
MessageChannel myChannel() {
    return new DirectChannel();
}

...
    .channel(myChannel())
    .log()
}

現在の MessageChannel が InterceptableChannel を実装しない場合、暗黙の DirectChannel と BridgeHandler が IntegrationFlow に注入され、WireTap がこの新しい DirectChannel に追加されます。次の例には、チャネル宣言がありません。

.handle(...)
.log()
}

前の例では(そしてチャネルが宣言されていないときはいつでも)、暗黙の DirectChannel が IntegrationFlow の現在の位置に注入され、現在構成されている ServiceActivatingHandler の出力チャネルとして使用されます(前述の .handle() から)。