Spring 使用队列中的消息,然后将这些消息写入文本文件

Spring 使用队列中的消息,然后将这些消息写入文本文件,spring,spring-integration,Spring,Spring Integration,我在下面写了一个spring集成程序,在这个程序中,我试图从队列中读取消息,然后将消息存储在计算机的c:驱动器中的一个文件中,就像没有创建文件一样,然后它将创建一个名为outputmessages.txt的新文件,但现在文件还没有准备好,你能告诉我哪里出了问题我怎样才能克服这一点 <int:channel id="output" > </int:channel> <bean id="tibcoEMSJndiTemplate" class="org.sp

我在下面写了一个spring集成程序,在这个程序中,我试图从队列中读取消息,然后将消息存储在计算机的c:驱动器中的一个文件中,就像没有创建文件一样,然后它将创建一个名为outputmessages.txt的新文件,但现在文件还没有准备好,你能告诉我哪里出了问题我怎样才能克服这一点

 <int:channel id="output"  > 

  </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://abc.net:2333</prop>
<prop key="java.naming.security.principal">wert</prop>
<prop key="java.naming.security.credentials">wert</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>abc.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="abc.test.data"  connection-factory="tibcoEMSConnFactory" /> 

<jms:message-driven-channel-adapter channel="filesIn"   concurrent-consumers="2"  destination-name="abc.test.data" connection-factory="tibcoEMSConnFactory"   /> 

  <file:outbound-channel-adapter id="filesIn" auto-create-directory="true" filename-generator-expression="'messagesoutput.txt'"   
        directory="c:\\message\\" > 
     </file:outbound-channel-adapter>

</beans>

com.tibco.tibjms.naming.TibjmsInitialContextFactory
tcp://abc.net:2333
韦特
韦特
通用连接工厂
测试数据
错误的
120000

我在您的配置中看到了第一个问题:

directory=“c:\messagesoutput.txt”

它必须是目录,而不是文件路径

另一个问题。不清楚您是要为每条消息创建一个文件,还是将它们全部添加到同一条消息中

对于最后一种情况,请使用
mode=“APPEND”

对于
fileName
可以使用
fileName生成器表达式=“'messagesoutput.txt'”


另外,请不要混合使用不同版本的Spring Integration JAR。并尝试使用
versionless
schemaLocation

您在通道
输出上没有消费者。只需删除
output
并使用
input
-消息驱动适配器将其消息发送到出站适配器(jms和文件-如果您将
input
添加为文件适配器上的通道)。@Gary Russell感谢您的建议,但是rite现在我关心的是将消息存储在计算机C:L驱动器的s目录中的测试文件中,你能纠正上面的xml并建议我需要做哪些必要的更改以实现同样的效果吗?我同意,我希望该文件存储在C:drive中名为inputmessage的目录中,我想说一下目录不是在C:drive中创建的,当它应该创建时,如果它是创建的,那么每次当我的应用程序运行时,这个目录应该首先清空,我希望应该有一个包含所有消息细节的单一文件,因此换句话说,只有一个文本文件包含队列的所有文本消息,请您对我上面的xml本身进行必要的更正,以实现这一点。请您在启动应用程序时删除该目录,例如,使用
并为您的
添加
自动创建目录=“true”
。注意:我们不打算为您工作。请阅读更多文档并深入挖掘示例。我已经按照建议更改了配置,现在我可以看到创建的目录,但文件中的消息没有写入文本文件,换句话说,文件根本没有在消息文件夹中创建没有意义。请共享StackTrace,例外情况除外,如果有。我已经更新了我的xml,正如我在本地文件夹中c:drive中看到的,名为message已创建,但在message文件夹中没有名为messagesoutput.txt的文本文件,因为我希望创建messagesoutput.txt文件,其中包含所有队列消息。请告知我上述更新的xml中的错误