Search in sources :

Example 1 with WireTap

use of org.springframework.integration.channel.interceptor.WireTap in project spring-integration by spring-projects.

the class MessageChannelSpec method wireTap.

/**
 * Populate the {@code Wire Tap} EI Pattern specific
 * {@link org.springframework.messaging.support.ChannelInterceptor} implementation.
 * @param wireTapSpec the {@link WireTapSpec} to build {@link WireTap} instance.
 * @return the current {@link MessageChannelSpec}.
 * @see WireTap
 */
public S wireTap(WireTapSpec wireTapSpec) {
    WireTap interceptor = wireTapSpec.get();
    this.componentsToRegister.put(interceptor, null);
    return interceptor(interceptor);
}
Also used : WireTap(org.springframework.integration.channel.interceptor.WireTap)

Example 2 with WireTap

use of org.springframework.integration.channel.interceptor.WireTap in project spring-integration by spring-projects.

the class IntegrationFlowDefinition method wireTap.

/**
 * Populate the {@code Wire Tap} EI Pattern specific
 * {@link org.springframework.messaging.support.ChannelInterceptor} implementation
 * to the current {@link #currentMessageChannel}.
 * <p> It is useful when an implicit {@link MessageChannel} is used between endpoints:
 * <pre class="code">
 * {@code
 *  .transform("payload")
 *  .wireTap(new WireTap(tapChannel().selector(m -> m.getPayload().equals("foo")))
 *  .channel("foo")
 * }
 * </pre>
 * This method can be used after any {@link #channel} for explicit {@link MessageChannel},
 * but with the caution do not impact existing {@link org.springframework.messaging.support.ChannelInterceptor}s.
 * @param wireTapSpec the {@link WireTapSpec} to use.
 * <p> When this EIP-method is used in the end of flow, it appends {@code nullChannel} to terminate flow properly,
 * Otherwise {@code Dispatcher has no subscribers} exception is thrown for implicit {@link DirectChannel}.
 * @return the current {@link IntegrationFlowDefinition}.
 */
public B wireTap(WireTapSpec wireTapSpec) {
    WireTap interceptor = wireTapSpec.get();
    if (this.currentMessageChannel == null || !(this.currentMessageChannel instanceof ChannelInterceptorAware)) {
        this.implicitChannel = true;
        channel(new DirectChannel());
    }
    addComponent(wireTapSpec);
    ((ChannelInterceptorAware) this.currentMessageChannel).addInterceptor(interceptor);
    return _this();
}
Also used : DirectChannel(org.springframework.integration.channel.DirectChannel) WireTap(org.springframework.integration.channel.interceptor.WireTap) ChannelInterceptorAware(org.springframework.integration.channel.ChannelInterceptorAware)

Example 3 with WireTap

use of org.springframework.integration.channel.interceptor.WireTap in project spring-integration by spring-projects.

the class WireTapParserTests method wireTapTimeouts.

@Test
public void wireTapTimeouts() {
    int defaultTimeoutCount = 0;
    int expectedTimeoutCount = 0;
    int otherTimeoutCount = 0;
    for (WireTap wireTap : wireTaps) {
        long timeout = ((Long) new DirectFieldAccessor(wireTap).getPropertyValue("timeout")).longValue();
        if (timeout == 0) {
            defaultTimeoutCount++;
        } else if (timeout == 1234) {
            expectedTimeoutCount++;
        } else {
            otherTimeoutCount++;
        }
    }
    assertEquals(4, defaultTimeoutCount);
    assertEquals(1, expectedTimeoutCount);
    assertEquals(0, otherTimeoutCount);
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) WireTap(org.springframework.integration.channel.interceptor.WireTap) Test(org.junit.Test)

Aggregations

WireTap (org.springframework.integration.channel.interceptor.WireTap)3 Test (org.junit.Test)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 ChannelInterceptorAware (org.springframework.integration.channel.ChannelInterceptorAware)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1