【问题标题】:Process cxf request with amq使用 amq 处理 cxf 请求
【发布时间】:2018-01-04 04:47:10
【问题描述】:

我想做这样的解决方案:

  1. cxf https soap 服务获取请求并将其发送到activemq队列 1
  2. 服务实现从队列 1 中获取消息,对其进行处理并 放入队列 2
  3. 端点从队列 2 获得响应并发送 回复客户

现在,我提出了一种解决方案,但我不确定如何处理来自 activemq 的响应并将其作为 SOAP 响应发回。下面是我的骆驼蓝图。端点蓝图:

    <?xml version="1.0" encoding="UTF-8"?>
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
           xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
           xmlns:soap="http://cxf.apache.org/blueprint/bindings/soap"
           xsi:schemaLocation="
             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
             http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
             http://cxf.apache.org/blueprint/bindings/soap http://cxf.apache.org/schemas/configuration/blueprint/soap.xsd">
    <bean id="cardServiceEndpoint" class="com.endpoint.card.CardEndpoint">
        <argument>
            <reference interface="com.card.CardService" />
        </argument>
    </bean>
    <cxf:cxfEndpoint
        id="cardEndpoint" 
        address="https://host:port/soa/card"
        serviceClass="com.card.CardService">
        <cxf:properties>
            <entry key="schema-validation-enabled" value="true" />
        </cxf:properties>
    </cxf:cxfEndpoint>
    <bean id="jaxB" class="org.apache.camel.model.dataformat.JaxbDataFormat">
        <property name="prettyPrint" value="true" />
        <property name="contextPath" value="com.type.card" />
    </bean>
    <camelContext id="endpoint-card-cxf" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="endpoint-soap-in">
            <from uri="cxf:bean:cardEndpoint"/>
            <transform>
                <simple>${body[0]}</simple>
            </transform>
            <marshal ref="jaxB"/>
            <setHeader headerName="JMSType">
                <simple>${headers.operationName}</simple>
            </setHeader>
            <to uri="amq:q.in"/>
        </route>
        <route id="endpoint-soap-out">
            <from uri="amq:q.out" />
            <unmarshal ref="jaxB" />
            <!-- STUCK HERE :( -->
        </route>
    </camelContext>
</blueprint>

服务处理器蓝图:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
           xsi:schemaLocation="
             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
    <bean id="cardService" class="com.card.impl.DefaultCardService">
        <argument>
            <reference interface="com.base.StashService"/>
        </argument>
    </bean>
    <service interface="com.card.CardService" ref="cardService" />
    <bean id="amqCardServiceEndpoint" class="com.card.endpoint.AmqCardEndpoint">
        <argument ref="cardService" />
    </bean>
    <bean id="jaxB" class="org.apache.camel.model.dataformat.JaxbDataFormat">
        <property name="prettyPrint" value="true" />
        <property name="contextPath" value="com.type.base:com.type.card" />
    </bean>
    <camelContext id="service-card-cx" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="card-rq-broker">
            <from uri="amq:queue:q.in?asyncConsumer=true" />
            <unmarshal ref="jaxB" />
            <doTry>
                <bean ref="amqCardServiceEndpoint" method="invoke" />
                <doCatch>
                    <exception>com.type.base.BaseException</exception>
                    <setBody>
                        <simple>${exception.getFaultInfo()}</simple>
                    </setBody>
                </doCatch>
            </doTry>
            <marshal ref="jaxB" />
            <to uri="amq:q.out" />
        </route>
    </camelContext>
</blueprint>

有什么帮助或建议吗?

【问题讨论】:

    标签: soap apache-camel cxf activemq jbossfuse


    【解决方案1】:

    使用jmsReplyTo 指定Camel 用于侦听响应的回复队列的名称(如果您想要一个固定的队列名称)。在 Camel JMS 文档中查看有关请求/回复的更多信息。

    <to uri="amq:q.in?jmsReplyTo=q.out"/>
    // continue here when reply is back
    

    【讨论】:

    • 嗨,克劳斯,感谢您的回复!我可以从 q.out 读取消息,我不确定如何将其发送回发起 SOAP 请求的客户端..
    • @IDeveloper,您不必将其发回。就像克劳斯所说的那样,在&lt;to uri="amq:q.in?jmsReplyTo=q.out"/&gt;之后添加你需要的任何处理。在路由结束时设置为交换主体的任何内容都将用作对您的 WS 的响应。查看您的蓝图,我会说您可以删除“endpoint-soap-out”路线,而只需在“endpoint-soap-in”路线的末尾添加&lt;unmarshal ref="jaxB" /&gt;
    • @noMad17 嗨,感谢您的解释。我尝试了这种方法,但似乎消息在&lt;to uri="amq:q.in?jmsReplyTo=q.out"/&gt; 处丢失了。如果我在to 节点之后放置一个&lt;log message="body: ${body}" /&gt; - 什么都不会发生..
    • 确保在将消息发送到您的队列之前将ExchangePattern 设置为InOut。还要确保从队列中消费的路由实际上正在接收消息。
    • @noMad17 从q.in 消耗的路由工作正常。现在我收到警告Reply received for unknown correlationID [id_here] on reply destination [queue://q.out]
    猜你喜欢
    • 1970-01-01
    • 2013-02-25
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 2011-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多