MessageChannelSpec.wireTap()

Spring Integration 包含一个 .wireTap() fluent API MessageChannelSpec 构建器。以下示例演示如何使用 wireTap 方法记录输入:

Spring Integration includes a .wireTap() fluent API MessageChannelSpec builders. The following example shows how to use the wireTap method to log input:

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

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

如果 MessageChannelInterceptableChannel 的一个实例,则 log(), wireTap()intercept() 运算符将应用于当前的 MessageChannel。否则,一个中间 DirectChannel 会被注入到与当前配置的端点相应的流程中。在以下示例中,WireTap 拦截器被直接添加到 myChannel,因为 DirectChannel 实现了 InterceptableChannel:

If the MessageChannel is an instance of InterceptableChannel, the log(), wireTap() or intercept() operators are applied to the current MessageChannel. Otherwise, an intermediate DirectChannel is injected into the flow for the currently configured endpoint. In the following example, the WireTap interceptor is added to myChannel directly, because DirectChannel implements InterceptableChannel:

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

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

当当前的 MessageChannel 没有实现 InterceptableChannel 时,一个隐式的 DirectChannelBridgeHandler 会被注入到 IntegrationFlow 中,并且 WireTap 会被添加到这个新的 DirectChannel。以下示例没有声明任何通道:

When the current MessageChannel does not implement InterceptableChannel, an implicit DirectChannel and BridgeHandler are injected into the IntegrationFlow, and the WireTap is added to this new DirectChannel. The following example does not have any channel declaration:

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

在前面给出的例子中(以及任何时候都没有声明通道),会将一个隐式的 DirectChannel 注入到 IntegrationFlow 的当前位置,并将其用作当前配置的 ServiceActivatingHandler(来自 .handle(),前面已经介绍过) 的输出通道。

In the preceding example (and any time no channel has been declared), an implicit DirectChannel is injected in the current position of the IntegrationFlow and used as an output channel for the currently configured ServiceActivatingHandler (from the .handle(), described earlier).