通过spring集成从队列中消耗字符串和对象消息

时间:2016-02-22 16:48:13

标签: jms spring-integration

我有一个队列,其中也可以有文本消息和对象消息我的任务是如果队列中有待处理的消息然后使用它们并写入文件中发生的文件但是它没有发生如果是对象消息

所以请告知我将如何使用并将对象消息简单地写入文本文件,例如下面是包含对象消息的队列

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>

1 个答案:

答案 0 :(得分:0)

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

或者您可以在jms和文件适配器之间放置一个<object-to-string-transformer/> - 它将是String对象的无操作,并将在对象上调用toString()

如果您只想丢弃这些对象,请将它们发送到nullChannel

请阅读reference document以获取有关这些组件的信息。

相关问题