Java Spring集成:将json中的对象发送到jms

Java Spring集成:将json中的对象发送到jms,java,json,jms,spring-integration,Java,Json,Jms,Spring Integration,我有点困惑,我需要一些澄清: 我正在尝试用json转换一个对象,并每秒使用jms发送它 以下是my context.xml: <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> <property name="targetConnectionFactory"> <bean class="org

我有点困惑,我需要一些澄清:

我正在尝试用json转换一个对象,并每秒使用jms发送它

以下是my context.xml:

<bean id="connectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://localhost:61616" />
        </bean>
    </property>
    <property name="sessionCacheSize" value="10" />
</bean>
<bean id="requestTopic" class="org.apache.activemq.command.ActiveMQTopic">
    <constructor-arg value="testconf" />
</bean>

<bean id="confbean" class="demo.DeviceConfiguration">
    <property name="id" value="THERMO_001" />
    <property name="name" value="thermometer" />
</bean>

<int:channel id="deadChannel"/>
<int:channel id="outboundChannel"/>
<int:channel id="objectToJsonChannel" />
<int:channel id="outJmsChannel" />
<int:channel id="requestChannel"/>

<int:gateway id="gateway"
    default-request-timeout="5000"
    default-reply-timeout="5000"
    default-request-channel="requestChannel"
    service-interface="demo.ServiceConfGateway">
</int:gateway>

<int:payload-type-router input-channel="requestChannel" default-output-channel="deadChannel">
    <int:mapping type="demo.DeviceConfiguration" channel="objectToJsonChannel"/>
</int:payload-type-router>

<int:object-to-json-transformer input-channel="objectToJsonChannel" output-channel="outJmsChannel" />

<int-jms:outbound-channel-adapter id="jmsout" channel="outJmsChannel" destination="requestTopic" />
我的主课需要这个循环吗?
这是可行的,但我想我可以简化它。

你可以用

<inbound-channel-adapter channel="requestChannel" expression="@dc">
   <poller fixed-delay="1000"/>
</inbound-channel-adapter>

有了它,你就不再需要
,因为你总是发送你需要的东西

从另一个角度:它会像你问的那样简单吗?。

只是为了完成。 下面是一种使用jms和主题每秒以json格式发送对象的简单方法:

<bean id="connectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://localhost:61616" />
        </bean>
    </property>
    <property name="sessionCacheSize" value="10" />
</bean>
<bean id="requestTopic" class="org.apache.activemq.command.ActiveMQTopic">
    <constructor-arg value="testconf" />
</bean>

<bean id="confbean" class="demo.DeviceConfiguration">
    <property name="id" value="THERMO_001" />
    <property name="name" value="thermometer" />
</bean>

<int:channel id="outJmsChannel" />
<int:channel id="requestChannel"/>

<int:inbound-channel-adapter channel="requestChannel" expression="@confbean">
    <int:poller fixed-delay="1000"/>
</int:inbound-channel-adapter>

<int:object-to-json-transformer input-channel="requestChannel" output-channel="outJmsChannel" />

<int-jms:outbound-channel-adapter id="jmsout" channel="outJmsChannel" destination="requestTopic" />


什么让你困惑/需要澄清?它不是像你想的那样工作吗?谢谢。这要简单得多。
<bean id="connectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://localhost:61616" />
        </bean>
    </property>
    <property name="sessionCacheSize" value="10" />
</bean>
<bean id="requestTopic" class="org.apache.activemq.command.ActiveMQTopic">
    <constructor-arg value="testconf" />
</bean>

<bean id="confbean" class="demo.DeviceConfiguration">
    <property name="id" value="THERMO_001" />
    <property name="name" value="thermometer" />
</bean>

<int:channel id="outJmsChannel" />
<int:channel id="requestChannel"/>

<int:inbound-channel-adapter channel="requestChannel" expression="@confbean">
    <int:poller fixed-delay="1000"/>
</int:inbound-channel-adapter>

<int:object-to-json-transformer input-channel="requestChannel" output-channel="outJmsChannel" />

<int-jms:outbound-channel-adapter id="jmsout" channel="outJmsChannel" destination="requestTopic" />