【发布时间】:2014-06-17 21:36:22
【问题描述】:
我想设置我的浏览器,类似于 Spring 示例中显示的示例,我敢打赌你们中的一些人熟悉它使用 websockets 和 stomp 来创建交互式 webapp。在这里:https://spring.io/guides/gs/messaging-stomp-websocket/
但是,我需要它通过一系列队列和使用骆驼路由它的应用程序,而不是直接通过消息传递并返回客户端并在页面上输出“Hello”+ 名称。我不太清楚如何将我的队列系统与浏览器连接起来。
这是我的骆驼上下文,目前在名为“testQSource”的队列中开始。我想使用 Stomp 将客户端提供给浏览器的输入消息发送到 testQSource,然后让它继续运行。
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="jms:queue:testQSource"/>
<to uri="myBean"/>
<log message="Routing message from testQSource to testQDestination queue with data ${body}"/>
<to uri="jms:queue:testQDestination"/>
<to uri="finalBean"/>
<log message="message: ${body}"/>
</route>
</camelContext>
<camel:camelContext id="camel-client">
<camel:template id="camelTemplate" />
</camel:camelContext>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
这是我的主要课程:
public class TestCamelSpring {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("camelspring.xml");
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
System.out.println("Message Sending started");
camelTemplate.sendBody("jms:queue:testQSource", "Sample Message");
System.out.println("Message sent");
}
}
我可以将 SpringApplication.run 滑入我的主函数并编辑 camelContext 还是我需要做更多的事情?我不确定如何将客户端输入发送到 testQSource。
我知道这很拗口,但我已经为此苦苦挣扎了一段时间,并且遇到了一些障碍。任何和所有的帮助将不胜感激!
【问题讨论】:
标签: spring websocket apache-camel stomp