【发布时间】:2018-08-20 22:14:05
【问题描述】:
我发现了很多不同的方法将我的窃听记录器转换为 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} " />
通道确实是可池化的,但我不明白为什么不需要为 XML 语法定义池化器?
这是我将其转换为 Java 的尝试(我的 SpEL 也不起作用):
@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();
}
===========
更新:
@Gary,我已经尝试了您的解决方案,但我得到了一些奇怪的效果。这是我在控制台中得到的:
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 上似乎每隔 x2 的 fixedRate 记录一次。
这是我的记录器和 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;
}
【问题讨论】:
标签: spring spring-boot spring-integration spring-el spring-integration-dsl