【问题标题】:apache camel routing queues issueapache骆驼路由队列问题
【发布时间】:2014-08-03 01:39:41
【问题描述】:

我正在尝试创建一个从浏览器获取信息并将其放入队列的应用程序。然后从队列中提取该数据并通过应用程序发送以确保安全。安全应用程序应在完成后将其放入不同的队列以由单独的操作应用程序拾取。

任何人都可以帮助我完成路由吗?基本上,我要找的路线是:

浏览器/UI -> Qnonsecure -> 安全应用 -> QSecure -> 操作应用

我现在的理解如下:

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="jms:queue:QnonSecure"/>
        <to uri="jms:queue:QSecure"/>
    </route>
</camelContext>

如何将其更改为往返应用程序的路由。 如何将来自浏览器的输入发送到 QnonSecure?另外,在我的代码中,我应该在 QnonSecure 和 QSecure 之间调用安全应用程序吗?

【问题讨论】:

    标签: spring routing apache-camel activemq message-queue


    【解决方案1】:

    有不止一种可能的解决方案。以以下路线为起点:

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="restlet:http://localhost:8081/myApp?restletMethod=post"/>
            <to uri="jms:queue:QnonSecure" pattern="InOut" />
            <enrich uri="direct:securityApp"/>
            <choice>
                <when>
                    <simple>${header.myHeader} == "SECURE"</simple>
                    <to uri="jms:queue:QSecure" pattern="InOut" />
                    <to uri="direct:actionApp" />
                </when>
                <otherwise>
                    <!-- handle non valid requests -->
                </otherwise>
            </choice>
        </route>
    </camelContext>
    

    步骤:

    1. 浏览器向 Camel restlet 组件发送 POST 请求。这可以通过 JavaScript、链接和/或只是一个普通的提交按钮来完成。
    2. 正文被发送到jms:queue:QnonSecure。当我们使用InOut 模式时,这是以同步方式完成的,并获取响应。
    3. jms:queue:QnonSecure 的响应被发送到测试凭据的direct:securityApp。如果它们正确,则标头 myHeader 将设置为 SECURE(或任何其他值)。
    4. choice 语句中,myHeader 被测试。在安全情况下,调用jms:queue:QSecure,最后调用direct:actionApp

    【讨论】:

    • 谢谢彼得。你似乎对骆驼和activemq非常了解。您主要是通过实践学习还是有其他快速熟悉的方法?第一个选项对我经验较少的骆驼头脑更有意义。如果 testQsource 不存在怎么办?如何将来自浏览器的输入发送到 testQdestination?另外,在我的代码中,我应该在 testQdestination 和 securityQ 之间调用安全应用程序吗?
    • @user3734863 如果testQsource不存在,则由ActiveMQ创建。使用 Camel 的 ProducerTemplate(参见 camel.apache.org/producertemplate.html)发送 JMS 消息。但是,如果您需要同步反馈,则根本不要使用 JMS。我想在你的情况下,这会让一切变得容易得多。
    • 再次感谢。如何将数据/消息从浏览器发送到 testQdestination,然后通过安全应用程序将 testQdestination 中的数据/消息发送到 Qsecure,然后再将它们发送到 actionApp?
    • 这太棒了,对我来说更有意义。非常感谢你所有的时间。丰富是我所缺少的很大一部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    相关资源
    最近更新 更多