我有點困惑,我需要一些澄清:Spring集成:在JSON對象發送給JMS
我想在JSON來變換對象,並使用JMS每秒發送。
這裏是我的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" />
在我的主類,我這樣做:
SpringApplication.run(DemoJmsApplication.class, args);
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
final DeviceConfiguration dc = ctx.getBean(DeviceConfiguration.class);
final ServiceConfGateway service = ctx.getBean(ServiceConfGateway.class);
while (true) {
service.send(dc);
Thread.sleep(1000);
}
我需要這個循環中,我的主類? 這是行得通的,但我想我可以簡化它。
什麼是混淆你/需要澄清?它是不是像你想要的那樣工作? – zapl