代码之家  ›  专栏  ›  技术社区  ›  WendyG

spring Integration配置日志记录通道适配器

  •  0
  • WendyG  · 技术社区  · 6 年前

    目前正在使用SpringIntegration4.2.8。

    关于这个问题,我已经解决了很多问题,但是我有一个xml配置,我不知道如何在新的配置类中替换:它是日志通道适配器,似乎没有匹配的类。

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

    如何在recipientListRouter中指定日志输出?

      <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>
    

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

    编辑-来自加里的回答 如果as看起来是明智的,这是最有可能的答案,我应该用哪种方式连接它,那么日志处理程序是否可以作为接收方?如果是这样,我还需要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 回复  |  直到 6 年前
        1
  •  2
  •   WendyG    6 年前

    它叫 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

    加里评论:

    消费端点由2个Bean组成:消费者(带有输入通道)和消息处理程序;XML生成这两个Bean;使用Java配置,@Bean创建处理程序,@ServiceActivator定义使用者。所以在您的例子中,应该是@ServiceActivator(inputChannel=“dlqLogger”)。路由器有选择器表达式。