I've found so many different ways of converting my wire-tap loggers into a Java config but none of them seem to work.
Here is my XML version :
<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} " />
The channel is indeed poolable but I don't understand why it is not necessary to define a pooler for the XML syntax ?
Here is my attempt at converting it to Java (my SpEL is not working either) :
@Bean
public IntegrationFlow logRequestingTasks(@Qualifier("defaultPoller") PollerMetadata defaultPoller) {
LoggingHandler loggingHandler = new LoggingHandler(LoggingHandler.Level.INFO.name());
loggingHandler.setLogExpressionString("'Requesting tasks : ' + headers.#{T(com.application.infrastructure.CommonConstants).KEY_TASK_NAME} + ' of ID : ' + headers.#{T(com.application.infrastructure.CommonConstants).KEY_TASK_ID} ");
loggingHandler.setLoggerName("logRequestingTasks");
return IntegrationFlows.from("tasksRequestChannel")
.handle(loggingHandler, e -> e.poller(defaultPoller))
.get();
}
==========
Update :
I've tried your solution, @Gary, but I've got some weird effects. Here is what I got in my console :
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.
It seems to log only once every x2 the fixedRate on my InboundChannelAdapter.
Here is my logger and InboundChannelAdapter :
@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;
}