Spring integration 如何在Spring集成中使用JavaDSL实现基于模式的通道拦截器?

Spring integration 如何在Spring集成中使用JavaDSL实现基于模式的通道拦截器?,spring-integration,Spring Integration,我们计划将我们的代码从SpringIntegrationXML迁移到DSL。在XML版本中,我们使用通道名模式进行跟踪 例如:如果频道名称有*\u EL.*,我们将拦截该频道并进行一些日志记录 如何在Java dsl中实现这种或更简单。GlobalChannel拦截器是为您准备的。它是Spring集成核心的一部分 所以,你必须这样做: @Bean public MessageChannel bar() { return new DirectChannel(); } @Bean @Glo

我们计划将我们的代码从SpringIntegrationXML迁移到DSL。在XML版本中,我们使用通道名模式进行跟踪

例如:如果频道名称有
*\u EL.*
,我们将拦截该频道并进行一些日志记录


如何在Java dsl中实现这种或更简单。

GlobalChannel拦截器是为您准备的。它是Spring集成核心的一部分

所以,你必须这样做:

@Bean
public MessageChannel bar() {
    return new DirectChannel();
}

@Bean
@GlobalChannelInterceptor(patterns = "*_EL_*")
public WireTap baz() {
    return new WireTap(this.bar());
}
我的意思是指定
ChannelInterceptor
@Bean
,并用该注释标记它以进行基于模式的拦截

更新

示例测试用例演示了从DSL流自动创建的
频道的
@GlobalChannelInterceptor
工作:

@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class SO31573744Tests {

    @Autowired
    private TestGateway testGateway;

    @Autowired
    private PollableChannel intercepted;

    @Test
    public void testIt() {
        this.testGateway.testIt("foo");
        Message<?> receive = this.intercepted.receive(1000);
        assertNotNull(receive);
        assertEquals("foo", receive.getPayload());
    }


    @MessagingGateway
    public interface TestGateway {

        @Gateway(requestChannel = "testChannel")
        void testIt(String payload);

    }

    @Configuration
    @EnableIntegration
    @IntegrationComponentScan
    public static class ContextConfiguration {

        @Bean
        public IntegrationFlow testFlow() {
            return IntegrationFlows.from("testChannel")
                    .channel("nullChannel")
                    .get();
        }

        @Bean
        public PollableChannel intercepted() {
            return new QueueChannel();
        }

        @Bean
        @GlobalChannelInterceptor(patterns = "*Ch*")
        public WireTap wireTap() {
            return new WireTap(intercepted());
        }

    }

}
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@肮脏的环境
公共类SO31573744测试{
@自动连线
专用测试网关;
@自动连线
截获的专用可轮询信道;
@试验
公开无效测试(){
this.testGateway.testIt(“foo”);
Message receive=this.intercepted.receive(1000);
assertNotNull(接收);
assertEquals(“foo”,receive.getPayload());
}
@消息网关
公共接口测试网关{
@网关(requestChannel=“testChannel”)
无效测试(字符串有效载荷);
}
@配置
@使能集成
@集成组件扫描
公共静态类上下文配置{
@豆子
公共集成流testFlow(){
返回IntegrationFlows.from(“testChannel”)
.频道(“空频道”)
.get();
}
@豆子
截获的公共可轮询频道(){
返回新的队列通道();
}
@豆子
@globalChannel拦截器(patterns=“*Ch*”)
公共窃听{
返回新的窃听(截获());
}
}
}

我用xml配置了_EL___截取器。但下面不是拦截器截取的。有什么想法吗?IntegrationFlows.from(“pushAssetId_EL_Channel”).transform(新的UpdateMetaDataTransformer())它对我来说没有意义。请分享你的配置,让我们相信我们有一个bug。我们将尽力为您提供解决方案。欢迎任何反馈。如果我调用xmlGateway,xml拦截器就会工作。如果我调用java dsl网关,java拦截器正在调用,但不是两者都在调用。请在我的回答中找到更新,并确认它也适用于您。并尝试使用最新的
DSL-1.0.2
版本,顺便说一句。它适用于
1.0.3
上的
master
在我上面的示例中,为什么在我点击DSL网关时没有调用xml拦截器类?。我理解@GlobalChannelInterceptor部分,但它只截取javadsl频道。