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

时间:2018-10-18 11:21:53

标签: configuration spring-integration

当前使用的是Spring Integration 4.2.8。

我已经解决了很多以前的问题,但是我有1条xml配置,我不知道如何在新的配置类中进行替换:它是logging-channel-adapter那里没有似乎是一个匹配的类。

我唯一可以找到的类是LoggingChannelAdapterParser,但这只是为了读取xml并输出某些内容(AbstractBeanDefinition)

如何在accepterListRouter中指定日志记录输出?

  <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' ")
  }

编辑-从加里的答案 如果看起来合理,这是最有可能的答案,我应该以哪种方式进行连线,日志记录处理程序可以成为接收者吗?如果是这样,我还需要ServiceActivator批注吗? 还是两种关系?

@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;
}

1 个答案:

答案 0 :(得分:1)

它称为LoggingHandler-参见the documentation

@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;
}

Artem Bilan的编辑

还要注意<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

来自Gary的评论:

消费端点由2个bean组成;使用者(具有输入通道)和消息处理程序; XML生成两者;使用Java配置,@ Bean创建处理程序,而@ServiceActivator定义使用者。因此,在您的情况下,它将是@ServiceActivator(inputChannel =“ dlqLogger”)。路由器具有选择器表达式。 –