【问题标题】:Enabling logging in spring integration utility在 spring 集成实用程序中启用日志记录
【发布时间】:2016-02-28 06:04:21
【问题描述】:

下面我有发送消息和消费队列消息的程序,现在我已经注释掉了发送部分,只想消费队列中的消息

现在我想在下面的程序中启用日志记录,以便在我的 c: 驱动器中生成一个日志文件,并且在该日志文件中它应该指示它在什么时间戳上消耗了什么消息,请告知如何配置登录下面的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:jms="http://www.springframework.org/schema/integration/jms"
    xmlns:file="http://www.springframework.org/schema/integration/file"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd 
    http://www.springframework.org/schema/integration/jms 
    http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd 
    http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/integration/file
    http://www.springframework.org/schema/integration/file/spring-integration-file.xsd    
    http://www.springframework.org/schema/context/spring-context.xsd">


    <int:poller id="poller" default="true">
        <int:interval-trigger interval="200" />
    </int:poller>



    <int:channel id="input">
        <int:queue capacity="10" />
    </int:channel>

    <bean id="tibcoEMSJndiTemplate" class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
            <props>
                <prop key="java.naming.factory.initial">com.tibco.tibjms.naming.TibjmsInitialContextFactory
                </prop>
                <prop key="java.naming.provider.url">tcp://lsdrtems2.fm.crdgrp.net:7333</prop>
                <prop key="java.naming.security.principal">acfgtir</prop>
                <prop key="java.naming.security.credentials">acfgtir</prop>
            </props>
        </property>
    </bean>

    <bean id="tibcoEMSConnFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="tibcoEMSJndiTemplate" />
        </property>
        <property name="jndiName">
            <value>GenericConnectionFactory</value>
        </property>
    </bean>

    <bean id="tibcosendJMSTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
            <ref bean="tibcoEMSConnFactory" />
        </property>
        <property name="defaultDestinationName">
            <value>acfgtirrtyation.ioa.swretift_publish_poc1</value>
        </property>
        <property name="pubSubDomain">
            <value>false</value>
        </property>
        <property name="receiveTimeout">
            <value>120000</value>
        </property>
    </bean>




    <!-- <jms:outbound-channel-adapter channel="input" 
        destination-name="acfgtirrtyation.ioa.swretift_publish_poc1" connection-factory="tibcoEMSConnFactory" /> -->

<int:channel id="objetChannel"></int:channel>
<int:channel id="StringChannel"></int:channel>
<int:channel id="jmsInChannel" />



<jms:message-driven-channel-adapter id="jmsIn" concurrent-consumers="10"
        destination-name="acfgtirrtyation.ioa.swretift_publish_poc1"  connection-factory="tibcoEMSConnFactory" extract-payload="false"
        channel="jmsInChannel" />

    <int:payload-type-router input-channel="jmsInChannel">
    <int:mapping type="javax.jms.ObjectMessage" channel="objetChannel" />
     <int:mapping type="javax.jms.TextMessage" channel="StringChannel" />
    </int:payload-type-router>



 <file:outbound-channel-adapter id="filesoutOject"  channel="objetChannel" directory="C:\\abcsaral"
 filename-generator="generatorr" />



 <file:outbound-channel-adapter id="filesoutString"  channel="StringChannel" directory="C:\\abcsaral"
 filename-generator="generatorr" />

<bean id="generatorr" class="com.abs.tibco.TimestampTextGenerator">
    </bean>


</beans>

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    将 log4j(或 logback,或任何由 commons-logging 支持的 java 日志系统)添加到您的类路径,并将其配置为记录类别 org.springframework.integration 的 DEBUG 级别。

    或者您可以将wire tap 添加到通道并将其路由到记录通道适配器

    <int:channel id="in">
        <int:interceptors>
            <int:wire-tap channel="logger"/>
        </int:interceptors>
    </int:channel>
    
    <int:logging-channel-adapter id="logger" level="DEBUG"/>
    

    【讨论】:

    • 谢谢,我正在考虑引入窃听器,以检查频道内发生的情况
    • 是的;您也可以这样做 - 我在您发布此评论的同时编辑了答案。
    • 谢谢 Gary,您能否解释一下有关日志记录通道适配器的信息,如果您可以将其添加到上述任何一个通道中以便我掌握,那就太好了。
    • 查看我指给您的文档;这很简单; this sample app 有一个。
    • 请问,步骤详细吗?我有一个带有 http-outbound-gateway 的链。我将输入通道中的名称用于日志通道。 。在上面的答案中添加了日志记录通道适配器。但我看到一条消息 - 将 {bridge:null} 添加为“dest-channel”频道的订阅者。频道“application.dest-channel”有 2 个订阅者。我不明白 - “将其配置为记录 org.springframework.integration 类别的 DEBUG 级别”
    猜你喜欢
    • 2011-09-22
    • 2011-07-11
    • 1970-01-01
    • 2013-07-14
    • 2018-11-23
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    相关资源
    最近更新 更多