【问题标题】:logging the messages of queue to a text file将队列的消息记录到文本文件
【发布时间】:2015-04-01 07:19:44
【问题描述】:

我有一个下面的 spring 集成 xml,我在其中向队列发送一条消息,该消息最终被消费并显示在控制台上,但现在我想自定义它可以说应该最终写入那些消费的消息(换句话说这些消息需要记录在一个文本文件中,并且该文本文件应该保存在我文件夹的 C: 驱动器中,文件的名称是 messageslog.txt

请告知我如何在 spring 集成中添加这样的功能来实现这个功能我已经知道在 spring 集成中像文件出站通道适配器这样的东西会有所帮助

下面是我的spring integtaion xml

<?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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
            http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
            http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

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

    <int:channel id="output">
        <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://labc.net:7033</prop>
                <prop key="java.naming.security.principal">wer</prop>
                <prop key="java.naming.security.credentials">wer</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 local="tibcoEMSConnFactory" />
        </property>
        <property name="defaultDestinationName">
            <value>test.data</value>
        </property>
        <property name="pubSubDomain">
            <value>false</value>
        </property>
        <property name="receiveTimeout">
            <value>120000</value>
        </property>
    </bean>

    <int:channel id="input">

    </int:channel>

    <jms:outbound-channel-adapter channel="input"
        destination-name="test.data" connection-factory="tibcoEMSConnFactory" />

    <jms:message-driven-channel-adapter
        channel="output" destination-name="test.data" connection-factory="tibcoEMSConnFactory" />

</beans>

【问题讨论】:

    标签: spring spring-integration spring-jms


    【解决方案1】:
    • input 更改为&lt;publish-subscribe-channel/&gt;
    • 在 jms 出站通道适配器上设置 order="1"
    • 使用order="2" 订阅文件出站通道适配器(模式=APPEND)

    默认情况下,仅当发送到 JMS 成功时才会调用文件适配器。

    output 上似乎没有消费者;但是,为避免消息丢失,output 应该QueueChannel,只需删除 &lt;queue/&gt; 元素(并且您不需要轮询器)。

    【讨论】:

    • 谢谢,您能否解释一下为什么应该将输入通道更改为发布订阅通道以及如果我将 jms 出站通道适配器的值设置为 order =1 在编程方面有什么好处? .提前致谢
    • 您需要一个发布-订阅通道,因为没有来自 jms 出站适配器的“回复”可以发送到任何地方。因此,我们使用 pub/sub 以便两个消费者(订阅者)按顺序获取消息。它们将按照声明的顺序被调用,但我更喜欢显式的order="..." 属性,以便其他阅读配置的人清楚地知道首先调用 jms,然后是文件适配器。
    猜你喜欢
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多