2015-04-01 67 views
0

我有一個彈簧下集成xml,其中我發送消息到隊列中,並且該消息最終被消耗並顯示在控制檯上,但現在我想定製它可以說那些消息是在文本文件中應該最終寫入(換句話說,這些消息需要被記錄)並且該文本文件應該保存在我的文件夾的C:驅動器中文件的名稱是messageslog.txt將隊列的消息記錄到文本文件

請告知如何我可以在春天集成本身添加這樣的功能,以acheieve這個功能我已經知道,在春天集成東西像文件出站通道適配器將幫助

下面是我的sprin克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> 

回答

0
  • 變化input<publish-subscribe-channel/>
  • order="2"

設置order="1"的JMS出站通道適配器

  • 訂閱文件的出站信道適配器(模式= APPEND)上默認情況下,只有發送到JMS成功時纔會調用文件適配器。

    你似乎沒有消費者output;然而,爲了避免消息丟失,output應該不是是一個QueueChannel,只是刪除<queue/>元素(你不需要一個輪詢)。

  • +0

    謝謝,請你解釋一下爲什麼輸入通道應該改變爲發佈訂閱通道,以及如果我將jms出站通道適配器的值設置爲order = 1,那麼編程方面會有什麼好處。在此先感謝 – user1620642 2015-04-01 11:54:22

    +0

    您需要一個pub-sub頻道,因爲jms出站適配器沒有「回覆」可以發送到任何地方。因此,我們使用pub/sub,以便消費者(訂閱者)按順序獲取消息。它們將按照它們聲明的順序被調用,但我更喜歡使用顯式的'order =「...」'屬性來讓其他人清楚地看到jms先被調用的配置,然後是文件適配器。 – 2015-04-01 12:32:25