如何将消息从activemq队列传递给cxf客户端休息

时间:2015-03-25 14:50:27

标签: osgi apache-camel cxf activemq blueprint

我正在创建一条短信并将其放入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>

任何人都能帮帮我吗? 感谢

1 个答案:

答案 0 :(得分:0)

两个路由都侦听 activemq:queue:LOG.ME 。 ActiveMQ中的队列将使用该消息,而任何其他队列都不会收到该消息。你需要做两件事之一:

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

  3. 有两种方法可以实现这一目标:

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

    2. 关于此的文档不​​是很清楚,但您可以使用setHeader:

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

    3. 此表达式可以是<bean><groovy>嵌入式表达式等。