【问题标题】:Spring, Camel, ActiveMQ, and WebSocketsSpring、Camel、ActiveMQ 和 WebSockets
【发布时间】: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


    【解决方案1】:

    如果您不想编写任何java代码将消息发送到消息队列,您可以考虑通过使用计时器来设置客户端骆驼上下文来触发消息发送,那么您只需要启动Spring上下文.

    <camel:camelContext id="camel-client">
        <camel:from uri="timer://foo?fixedRate=true&period=60000" />
        <camel:setBody>
           <simple>Simple Message!</simple>
        </camel:setBody>
        <camel:to uri="jms:queue:testQSource" /> 
    </camel:camelContext>
    

    【讨论】:

    • 这条路由只是每 60 秒向 testQSource 发送一次消息。
    猜你喜欢
    • 2015-04-04
    • 2018-10-02
    • 2018-01-31
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2018-03-17
    • 2021-12-17
    • 2016-02-02
    相关资源
    最近更新 更多