Jms 通过spring集成使用队列中的字符串和对象消息

Jms 通过spring集成使用队列中的字符串和对象消息,jms,spring-integration,Jms,Spring Integration,我有一个队列,其中可以有文本消息,也可以有对象消息。我的任务是,如果队列中有挂起的消息,则使用它们并写入一个文件,该文件在文本消息中发生,但在对象消息中不会发生 因此,请告知我将如何使用对象消息并将其写入文本文件中,例如下面的是包含对象消息的队列 ioa.exception.retry.object 现在,它包含对象消息,有时还包含字符串消息。我想使用上面队列中所有消息类型的消息 下面是我的配置,其中发送方部分我已注释掉,仅启用了消费者部分。请告知我如何克服消费对象消息问题 <?xml

我有一个队列,其中可以有文本消息,也可以有对象消息。我的任务是,如果队列中有挂起的消息,则使用它们并写入一个文件,该文件在文本消息中发生,但在对象消息中不会发生

因此,请告知我将如何使用对象消息并将其写入文本文件中,例如下面的是包含对象消息的队列

ioa.exception.retry.object
现在,它包含对象消息,有时还包含字符串消息。我想使用上面队列中所有消息类型的消息

下面是我的配置,其中发送方部分我已注释掉,仅启用了消费者部分。请告知我如何克服消费对象消息问题

<?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://lrtys2.fm.absgrp.net:745</prop>
                <prop key="java.naming.security.principal">xyz</prop>
                <prop key="java.naming.security.credentials">xyz</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>ioa.exception.retry.object</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="ioa.exception.retry.object" connection-factory="tibcoEMSConnFactory" />


<jms:message-driven-channel-adapter id="jmsIn" concurrent-consumers="10"
        destination-name="ioa.exception.retry.object"  connection-factory="tibcoEMSConnFactory"
        channel="jmsInChannel" />

    <int:channel id="jmsInChannel" />



 <file:outbound-channel-adapter id="filesout"  channel="jmsInChannel" directory="C:\\asdel"
 filename-generator="generatorr" />

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




</beans>

com.tibco.tibjms.naming.TibjmsInitialContextFactory
tcp://lrtys2.fm.absgrp.net:745
xyz
xyz
通用连接工厂
ioa.exception.retry.object
假的
120000

这取决于你想对对象做什么;您可以在jms适配器和文件适配器之间添加负载类型路由器-直接将字符串发送到文件适配器,将对象发送到
以转换为字符串,然后发送到文件适配器

或者,您可以在jms和文件适配器之间放置一个
,它将对String对象不起作用,并将对该对象调用
toString()

如果只想丢弃对象,请将其发送到
nullChannel


有关这些组件的信息,请阅读。

谢谢,第一个选项非常完美。请您展示一下路由器如何在运行时验证消息是否为字符串1或对象1,以及如何在jms适配器和文件适配器之间连接路由器。请先阅读文档,如果需要,请返回此处有些事情你不明白。