【问题标题】:Mule 3 async-replyMule 3 异步回复
【发布时间】:2012-07-11 15:58:24
【问题描述】:

我有一个通过网络服务接收请求的流程。我使用组件绑定将该请求转发到 JMS 队列。但是,我想从该队列中获取异步回复并将其用作对 Web 服务的响应。我需要在流程中使用 reply-to 和 async-reply-router 吗?或者在Mule 3中有没有其他方法可以做到这一点?有什么指点吗?

<flow name="mviService">
    <http:inbound-endpoint address="http://localhost:62005/mvi"
        exchange-pattern="request-response">
        <cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
    </http:inbound-endpoint>
    <component class="com.pennmutual.services.mvi.MVIServiceImpl">
        <binding interface="com.pennmutual.mvi.helper.XMLReqProcessorInterface"
            method="process121Order">
            <jms:outbound-endpoint queue="mviq.121.order" />
        </binding>
            </component>

            <async-reply>

            </async-reply>

      </flow>

============ 已编辑 - 请参阅下面的重新设计的问题 =================

我认为我在描述场景方面做得不好。让我再试一次。这是场景--

  1. 客户端调用我们在此流程“mviService”中描述的服务。 mviService 通过基于 HTTP/SOAP 的入站端点获取 XML 请求。我们将此请求称为 XML121Request.4
  2. 在 MVI“com.xyz.services.mvi.MVIServiceImpl”中定义的组件对 XML121Request 进行了一些更改。
  3. 将此 XML121 转发到 JMS 队列“mviq.121.order”。它为此使用组件绑定。
  4. 此 JMS 队列的出站端点是转发此请求的第三方 Web 服务。第三方确认收到 XML121 并返回同步 Web 服务调用。
  5. 来自第三方服务的响应在稍后的时间点出现,通常为几秒钟。响应是异步的。第三方调用 MVI 上的另一个 Web 服务端点并发送 XML121Response。
  6. MVI 将此响应放入名为“mviq.async.service.reply”的 JMS 队列中。
  7. “mviService”流程需要等待此响应并将此响应(经过一些修改)发送给调用方(在步骤 1 中)。

我能够从第三方获得响应,并且该响应被排入名为“mviq.async.service.reply”的队列中。我想使用/使用此消息并将其作为对第一次调用 MVI 的响应返回。

我正在尝试使用“请求-回复”。

    <request-reply timeout="60000">
        <vm:outbound-endpoint path="request" />
        <jms:inbound-endpoint queue="mviq.async.service.reply"
            exchange-pattern="one-way" />
    </request-reply>

问题是,即使在这种情况下我不想有出站端点,我仍然必须放置一个,因为这是请求-回复标签所要求的。流程在该时间点等待 60 秒,但即使我将某些内容放入队列“mviq.async.service.reply”,相关 ID 也不匹配,因此服务超时并返回错误。

流程如下所述。

<flow name="mviService">
    <http:inbound-endpoint address="http://localhost:62005/mvi"
        exchange-pattern="request-response">
        <cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
    </http:inbound-endpoint>
    <component class="com.pennmutual.services.mvi.MVIServiceImpl">
        <binding interface="com.xyz.mvi.helper.XMLReqProcessorInterface"
            method="process121Order">
            <jms:outbound-endpoint queue="mviq.121.order" />
        </binding>
    </component>

    <!-- <logger message="XML Correlation ID 1 is #[mule:message.headers(all)]" /> -->
    <request-reply timeout="60000">
        <vm:outbound-endpoint path="request" /> <!-- we don't care about this -->
        <jms:inbound-endpoint queue="mviq.async.service.reply"
            exchange-pattern="one-way" />
    </request-reply>
        <!-- <component class="com.xyz.mvi.CreateMVIServiceResponse"/> -->
</flow>

===== 回复到 ============== 的 FLow

<flow name="mviService">
    <http:inbound-endpoint address="http://localhost:62005/mvi"
        exchange-pattern="request-response">
        <cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
    </http:inbound-endpoint>
    <component class="com.xyz.services.mvi.MVIServiceImpl">
        <binding interface="com.xyz.mvi.helper.XMLReqProcessorInterface"
            method="process121Order">
            <jms:outbound-endpoint queue="mviq.121.order" exchange-pattern="request-response">
                <message-properties-transformer scope="outbound">
                    <add-message-property key="MULE_REPLYTO" value="mviq.async.service.reply" />
                </message-properties-transformer>
            </jms:outbound-endpoint>
        </binding>
     </component>
</flow>

【问题讨论】:

  • 如果将request-response 指定为exchange-patternexchange-pattern 会怎样?你不是这样得到同步响应的吗?
  • 问题是流程必须是单向的。原因是 jms:outbound-endpoint 流调用 Web 服务,并且来自该 Web 服务的响应在稍后的时间点(几秒钟内)通过另一个名为“mviq.async.service.reply”的 JMS 队列异步到来。我想在上面提到的流“mviService”中收听这个jms队列“mviq.async.service.reply”。
  • 如果在jms:outbound-endpoint 之前将JMSReplyTo 出站属性设置为mviq.async.service.reply(配置为request-response)会怎样。或者,将MULE_REPLYTO 出站属性设置为jms://mviq.async.service.reply
  • 大卫,我试图重新构建这个问题。如果您能在此基础上给我一些反馈,我将不胜感激。
  • 您不能在您的场景中使用request-reply。你试过我上面的建议了吗?

标签: mule


【解决方案1】:

我建议您不要创建服务组件类,而是使用cxf:proxy-service,这将使您能够直接访问 SOAP 信封并有机会在 XML 级别以您想要的方式组装响应。

这将使您摆脱服务组件类强加给您的约束,因此无需使用绑定并打开使用request-response 的大门。

查看this SO answer 并查看(瘦)proxy service user guide 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 2014-12-21
    • 2017-11-16
    • 1970-01-01
    相关资源
    最近更新 更多