Mule 3 异步回复

标签 mule

我有一个通过网络服务接收请求的流程。我使用组件绑定(bind)将该请求转发到 JMS 队列。但是,我想从该队列获取异步回复并将其用作对网络服务的响应。我需要在流程中使用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”。它为此使用组件绑定(bind)。
  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 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>

最佳答案

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

这将使您摆脱服务组件类强加给您的约束,从而免除使用绑定(bind)的需要并为使用请求-响应打开了大门。

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

关于Mule 3 异步回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11436667/

相关文章:

java - 如何转义JSON中的特殊字符

java - 如何公开位于 mule devkit 连接器中的 jax-ws?

ssl - Mule HTTPS 监听器不会响应

mule - 如何在 Data weaver : Mule 中检查空条件

java - 如何监控具有多个服务器/Mule 代理的 Mule 3 ESB 社区版?

maven - 不可解析的父 POM

java - 用于集成测试的嵌入式 Java HTTPS 服务器

maven - 如何修复 Maven Mulesoft 代码的构建错误

mule - 多个 DataWeave 函数中的优先级

java - 将 Maven 依赖项转移到 Ant