将wire tap从XML语法转换为Spring集成Java注释或DSL

将wire tap从XML语法转换为Spring集成Java注释或DSL,spring,spring-boot,spring-integration,spring-el,spring-integration-dsl,Spring,Spring Boot,Spring Integration,Spring El,Spring Integration Dsl,我已经找到了很多不同的方法将有线抽头记录器转换为Java配置,但它们似乎都不起作用 以下是我的XML版本: <int:channel id="tasksRequestChannel"> <int:queue capacity="${channel.queue.capacity}"/> <int:interceptors> <int:wire-tap channel="logRequestingTasks" />

我已经找到了很多不同的方法将有线抽头记录器转换为Java配置,但它们似乎都不起作用

以下是我的XML版本:

<int:channel id="tasksRequestChannel">
    <int:queue capacity="${channel.queue.capacity}"/>
    <int:interceptors>
        <int:wire-tap channel="logRequestingTasks" />
    </int:interceptors>
</int:channel>

<int:logging-channel-adapter id="logRequestingTasks" level="INFO"
    expression="'Requesting tasks : ' + headers.#{T(com.application.infrastructure.CommonConstants).KEY_TASK_NAME} + ' of ID : ' + headers.#{T(com.application.infrastructure.CommonConstants).KEY_TASK_ID} " />
==========

更新:

“我试过你的解决办法,”加里,但我有一些奇怪的效果。以下是我在控制台中得到的信息:

2018-08-21 13:22:50.347  INFO 7060 --- [ask-scheduler-3] T.RestTemplate                           : step=INIT;...
2018-08-21 13:22:50.564  INFO 7060 --- [ask-scheduler-3] T.RestTemplate                           : step=SUCCESS;...
2018-08-21 13:22:50.824  INFO 7060 --- [ask-scheduler-3] c.a.t.d.a.TasksSplitter            : No active task retrieved.
2018-08-21 13:23:20.343  INFO 7060 --- [ask-scheduler-9] logStartDmwProcess                       : Start of Application process.
2018-08-21 13:23:20.346  INFO 7060 --- [ask-scheduler-9] T.RestTemplate                           : step=INIT;...
2018-08-21 13:23:20.540  INFO 7060 --- [ask-scheduler-9] T.RestTemplate                           : step=SUCCESS;...
2018-08-21 13:23:20.555  INFO 7060 --- [ask-scheduler-9] c.a.t.d.a.TasksSplitter            : No active task retrieved.
在我的InboundChannelAdapter上的fixedRate上,它似乎每x2只记录一次

这是我的记录器和内置通道适配器:

@Bean
public IntegrationFlow logStartProcess() {       
    Expression logExpression = new SpelExpressionParser().parseExpression("'Start of Application process.'");
    return IntegrationFlows.from("initTimestampChannel")
                .log(Level.INFO, "logStartProcess", logExpression)
                .get();
}

@RefreshScope
@Bean
@InboundChannelAdapter(value = "initTimestampChannel", poller = @Poller(fixedRate = "30000"))
public MessageSource<?> buildTasksRequest() {
    MethodInvokingMessageSource source = new MethodInvokingMessageSource();
    source.setObject(tasksService);
    source.setMethodName("requestAllTasks");
    return source;
}
@Bean
公共集成流logStartProcess(){
表达式logExpression=new-SpelExpressionParser().parseExpression(“'Start of Application process.”);
返回IntegrationFlows.from(“initTimestampChannel”)
.log(Level.INFO,“logStartProcess”,logExpression)
.get();
}
@刷新范围
@豆子
@InboundChannelAdapter(value=“initTimestampChannel”,poller=@poller(fixedRate=“30000”))
public MessageSource buildTasksRequest(){
MethodInvokingMessageSource=新MethodInvokingMessageSource();
source.setObject(tasksService);
source.setMethodName(“requestAllTasks”);
返回源;
}

您可以使用
.wiretap()
方法,或者只需使用
.log()
方法(在内部创建一个窃听)

结果:

2018-08-20 20:19:44.777  INFO 4096 --- [           main] o.s.integration.handler.LoggingHandler   : Requesting tasks : aName of ID : anId
GenericMessage [payload=foo, headers={taskName=name, id=b21dde6e-bfa3-f727-52f0-056cb2775ee7, taskId=id, timestamp=1534810784776}]

这里不能使用SpEL的
{…}
构造。

谢谢Gary。我已经用我得到的奇怪结果更新了我的帖子。我还有两个问题:如何避免使用
.handle(System.out::println)
它会污染控制台,但当我在可轮询频道上删除它时,我会得到一个
无订户错误
。。。是否必须使用
IntegrationFlow
为我的可轮询通道记录器定义轮询器?您必须从通道中获取一些信息;System.out只是一个示例处理程序-您需要在XML版本中显示从
tasksRequestChannel
消耗的内容,然后我可以更新我的示例以匹配。此外,您不能将Spring集成组件放在
@RefreshScope
中,因为它只适用于被动组件,而不适用于集成流中的主动组件。
@SpringBootApplication
public class So51939181Application {

    private static final Expression logExpression = new SpelExpressionParser().parseExpression(
            "'Requesting tasks : ' + headers." + CommonConstants.KEY_TASK_NAME
            + " + ' of ID : ' + headers." + CommonConstants.KEY_TASK_ID);

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

    @Bean
    public IntegrationFlow flow() {
        return IntegrationFlows.from("foo")
                .log(logExpression)
                // .more stuff
                .handle(System.out::println)
                .get();
    }

    public static void main(String[] args) {
        SpringApplication.run(So51939181Application.class, args);
    }

    @Bean
    public ApplicationRunner runner(MessageChannel foo) {
        return args -> foo.send(MessageBuilder.withPayload("foo")
                .setHeader(CommonConstants.KEY_TASK_NAME, "name")
                .setHeader(CommonConstants.KEY_TASK_ID, "id")
                .build());
    }

}
2018-08-20 20:19:44.777  INFO 4096 --- [           main] o.s.integration.handler.LoggingHandler   : Requesting tasks : aName of ID : anId
GenericMessage [payload=foo, headers={taskName=name, id=b21dde6e-bfa3-f727-52f0-056cb2775ee7, taskId=id, timestamp=1534810784776}]