弹簧集成配置日志记录通道适配器



当前使用 Spring Integration 4.2.8。

我已经处理了很多我之前关于这个问题的问题,但我有 1 个 xml 配置,我无法弄清楚如何在新的配置类中替换:它是日志记录通道适配器,似乎没有匹配的类。

我能找到的唯一类是LoggingChannelAdapterParser,但它只是设计用于读取xml并输出一些东西(AbstractBeanDefinition(。

如何在收件人列表路由器中指定日志记录输出?

<int:logging-channel-adapter id="dlq-logger" level="ERROR" expression="'Unknown action type ['
.concat(headers.actionType)
.concat('] for message with payload ')
.concat(payload)"/>
<int:recipient-list-router input-channel="jms-inbound" id="action-type-router">
<int:recipient channel="inbound1" selector-expression="headers.actionType == 'CREATE'"/>
<int:recipient channel="inbound2" selector-expression="headers.actionType == 'UPDATE'"/>
<int:recipient channel="dlq-logger" selector-expression="headers.actionType != 'UPDATE' and headers.actionType != 'CREATE' "/>
</int:recipient-list-router>

这是 recipinetListRouter 构造函数

@ServiceActivator(inputChannel = "routingChannel")
@Bean
RecipientListRouter actionTypeRouter(){
RecipientListRouter router = new RecipientListRouter();
router.setChannels()
router.addRecipient("Inbound1", "headers.actionType == 'CREATE'")
router.addRecipient("Inbound2", "headers.actionType == 'UPDATE'")
router.addRecipient("dlqLogger", "headers.actionType != 'UPDATE' and headers.actionType != 'CREATE' ")
}

编辑 - 来自加里的回答 如果看起来很明智,这是我以哪种方式连接它最有可能的答案,那么日志记录处理程序可以成为收件人吗?如果是这样,我是否仍需要服务激活器注释? 还是双向关系?

@Bean
@ServiceActivator(inputChannel = "logChannel")
public LoggingHandler logging() {
LoggingHandler adapter = new LoggingHandler(LoggingHandler.Level.DEBUG);
adapter.setLoggerName("TEST_LOGGER");
adapter.setLogExpressionString("headers.id + ': ' + payload");
return adapter;
}

它被称为LoggingHandler- 请参阅文档。

@Bean
@ServiceActivator(inputChannel = "logChannel")
public LoggingHandler logging() {
LoggingHandler adapter = new LoggingHandler(LoggingHandler.Level.DEBUG);
adapter.setLoggerName("TEST_LOGGER");
adapter.setLogExpressionString("headers.id + ': ' + payload");
return adapter;
}

编辑自阿尔乔姆·比兰

还要注意<int:logging-channel-adapter>的文档:

<xsd:element name="logging-channel-adapter">
<xsd:annotation>
<xsd:documentation>
Defines a Message Producing Endpoint for the
'org.springframework.integration.handler.LoggingHandler'.
</xsd:documentation>
</xsd:annotation>

然后转到此文档以进一步了解模型:https://docs.spring.io/spring-integration/reference/html/overview.html#_finding_class_names_for_java_and_dsl_configuration

加里的评论:

使用端点由 2 个 bean 组成;一个使用者(带有输入通道(和消息处理程序;XML 生成两者;使用 Java 配置,@Bean创建处理程序,@ServiceActivator定义使用者。所以在你的例子中,它会是@ServiceActivator(inputChannel="dlqLogger"(。路由器具有选择器表达式。–

最新更新