【问题标题】:How to pass message from activemq queue to cxf client rest如何将消息从activemq队列传递到cxf客户端休息
【发布时间】:2015-03-25 14:50:26
【问题描述】:

我正在创建一条文本消息并将其放入 activemq 队列中,然后将其显示在日志中。现在我需要将此消息传递给 cxf rs 客户端以在参数中使用它。我正在使用蓝图来定义骆驼路线和 cxf 客户端。

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
default-activation="eager" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws" xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="
         http://www.osgi.org/xmlns/blueprint/v1.0.0 
         http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
         http://camel.apache.org/schema/blueprint/cxf 
         http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
         http://cxf.apache.org/blueprint/jaxrs 
         http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
         http://cxf.apache.org/configuration/security
         http://cxf.apache.org/schemas/configuration/security.xsd
         http://cxf.apache.org/transports/http/configuration
         http://cxf.apache.org/schemas/configuration/http-conf.xsd">

 <!-- Beans -->

<bean id="myTransform" class="cxfcamel.MyTransform"/>
<bean id="serviceBean" class="cxfcamel.GreetingService" />
<bean id="rsprocessor" class="cxfcamel.RSProcessor"/>



<!-- Web Services -->
<jaxrs:server id="customerService" address="http://localhost:7171  /customers">
    <jaxrs:serviceBeans>
        <ref component-id="serviceBean" />
    </jaxrs:serviceBeans>
</jaxrs:server>

<cxf:rsClient id="rsClient"
    address="http://localhost:7171/customers/entry-point/register/nosJ"
    serviceClass="cxfcamel.GreetingService">
</cxf:rsClient>


<!-- Camel Routes -->
<camelContext id="camel"
    xmlns="http://camel.apache.org/schema/blueprint">
    <route>
        <from uri="timer://projectTimer?repeatCount=1" />
        <bean ref="myTransform" method="transform" />
        <to uri="activemq:queue:LOG.ME" />
    </route>
    <route>
        <from uri="activemq:queue:LOG.ME" />
        <to uri="log:ExampleActiveMQRouterBlueprint" />
    </route>

    <route>
        <from uri="activemq:queue:LOG.ME" />
        <setHeader headerName="Content-Type">
            <constant>application/json</constant>
        </setHeader>
        <setHeader headerName="CamelHttpMethod">
            <constant>PUT</constant>
        </setHeader>
        <to uri="cxfrs:bean:rsClient" />
    </route>
</camelContext>

谁能帮帮我? 谢谢

【问题讨论】:

    标签: osgi apache-camel cxf activemq blueprint


    【解决方案1】:

    两个路由都监听 activemq:queue:LOG.ME 。 ActiveMQ 中的一个队列将消费该消息,而任何其他队列都不会接收该消息。您需要做 2 件事中的 1 件事:

    1. 将您的队列变成一个主题,以便两条路由都能收到消息。 Topic vs Queue
    2. 安排您的路线,以便只有一条路线正在监听 activemq:queue:LOG.ME

    有两种方法可以做到这一点:

    1. 将您的 cxfrs:bean:rsClient 调用转换为 cxfrs:http://localhost:7171/customers/entry-point/register/nosJ 并在末尾附加参数。

    2. 这方面的文档不是很清楚,但你也许可以使用 setHeader:

      <setHeader headerName="CamelCxfRsQueryMap"> expression which returns a map </setHeader>

    此表达式可以是&lt;bean&gt;&lt;groovy&gt; 嵌入表达式等。

    【讨论】:

    • 感谢您的回复,但我想将队列消息传递到 CXF RS 客户端中的 URL,以便我可以将其用作查询参数。例如:localhost:7171/customers/entry-point/register{Queue Message} 你能请帮帮我!!
    • 好的!这更有意义。我会更新我的答案。我在您的原始帖子中没有看到该信息,但我现在看到了 =)
    • 就我而言,我在 cxfrs 端点中有一个基本身份验证,如下所示:10.47.2.203:8080/rest/api/2/project/TM" serviceClass="cxfcamel.GreetingService" username=" username" password="password" > 我认为第一个建议不适用于我的情况!虽然我没有得到第二种方法!我应该声明一个包含 Map 的 bean 还是什么!!
    猜你喜欢
    • 2016-12-07
    • 2019-05-04
    • 2013-02-21
    • 2010-11-05
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多