21.5. 配置 WS-RM

21.5.1. 配置 Apache CXF 特定 WS-RM 属性

概述

要配置特定于 Apache CXF 的属性,请使用 rmManager Spring bean。在您的配置文件中添加以下内容:

例 21.4 “配置 Apache CXF 特定 WS-RM 属性” 显示了一个简单的示例。

例 21.4. 配置 Apache CXF 特定 WS-RM 属性

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://cxf.apache.org/ws/rm/manager http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd">
...
<wsrm-mgr:rmManager>
<!--
  ...Your configuration goes here
-->
</wsrm-mgr:rmManager>

rmManager Spring bean 的子项

表 21.2 “rmManager Spring Bean 的子项” 显示 http://cxf.apache.org/ws/rm/manager 命名空间中定义的 rmManager Spring bean 的子元素。

表 21.2. rmManager Spring Bean 的子项

元素描述

RMAsertion

类型为 RMA sertion 的元素

deliveryAssurance

Type DeliveryAsuranceType 的一个元素,用于描述应应用的交付保证

sourcePolicy

允许您配置 RM 源详情的 SourcePolicyType 的一个元素

destinationPolicy

允许您配置 RM 目的地详情的 DestinationPolicyType 的一个元素

示例

例如,请参阅 “最大未确认的消息阈值”一节

21.5.2. 配置标准 WS-RM 策略属性

概述

您可以使用以下方法之一配置标准 WS-RM 策略属性:

ws-Policy RMAsertion Children

表 21.3 “WS-Policy RMAsertion Element 的子项” 显示 http://schemas.xmlsoap.org/ws/2005/02/rm/policy 命名空间中定义的元素:

表 21.3. WS-Policy RMAsertion Element 的子项

名称描述

InactivityTimeout

指定在端点可以视为因为不活跃而终止的 RM 序列前必须收到消息的时长。

BaseRetransmissionInterval

设置确认在给定消息中的 RM Source 必须接收的时间间隔。如果在 BaseRetransmissionInterval 设置的时间内未收到确认,则 RM Source 将重新传输该消息。

ExponentialBackoff

指示将使用已知指数级 backoff 算法(Tanenbaum)调整重新传输间隔。

如需更多信息,请参阅 Computer Networks、Andrew S. Tanenbaum、Prentice Hall PTR, 2003。

AcknowledgementInterval

在 WS-RM 中,确认信息会在返回消息上发送或独立发送。如果无法发送确认消息的返回消息,则 RM Destination 可在发送独立确认前等待确认间隔。如果没有未确认的消息,RM Destination 可以选择不发送确认消息。

更详细的参考信息

有关更详细的参考信息,包括每个元素的子元素和属性的描述,请参阅 http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd

rmManager Spring bean 中的 RMAssertion

您可以通过在 Apache CXF rmManager Spring bean 中添加 RMA sertion 来配置标准 WS-RM 策略属性。如果您要在同一配置文件中保留所有 WS-RM 配置,则这是最好的方法。也就是说,如果要配置同一文件中特定于 Apache CXF 的属性和标准 WS-RM 策略属性。

例如,例 21.5 “使用 rmManager Spring Bean 中的 RMAsertion 配置 WS-RM 属性” 中的配置会显示:

  • 标准 WS-RM 策略属性 BaseRetransmissionInterval 使用 rmManager Spring bean 中的 RMAsertion 配置。
  • 在同一配置文件中配置 Apache CXF 特定 RM 属性 intraMessageThreshold

例 21.5. 使用 rmManager Spring Bean 中的 RMAsertion 配置 WS-RM 属性

<beans xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy"
       xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
...>
<wsrm-mgr:rmManager id="org.apache.cxf.ws.rm.RMManager">
    <wsrm-policy:RMAssertion>
        <wsrm-policy:BaseRetransmissionInterval Milliseconds="4000"/>
    </wsrm-policy:RMAssertion>
    <wsrm-mgr:destinationPolicy>
        <wsrm-mgr:acksPolicy intraMessageThreshold="0" />
    </wsrm-mgr:destinationPolicy>
</wsrm-mgr:rmManager>
</beans>

功能中的策略

您可以在功能中配置标准 WS-RM 策略属性,如 例 21.6 “在功能内将 WS-RM 属性配置为策略” 所示。

例 21.6. 在功能内将 WS-RM 属性配置为策略

<xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:wsa="http://cxf.apache.org/ws/addressing"
        xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xsi:schemaLocation="
http://www.w3.org/2006/07/ws-policy http://www.w3.org/2006/07/ws-policy.xsd
http://cxf.apache.org/ws/addressing http://cxf.apache.org/schema/ws/addressing.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <jaxws:endpoint name="{http://cxf.apache.org/greeter_control}GreeterPort" createdFromAPI="true">
        <jaxws:features>
               <wsp:Policy>
                   <wsrm:RMAssertion xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
                     <wsrm:AcknowledgementInterval Milliseconds="200" />
                   </wsrm:RMAssertion>
                   <wsam:Addressing xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata">
                       <wsp:Policy>
                            <wsam:NonAnonymousResponses/>
                       </wsp:Policy>
                   </wsam:Addressing>
              </wsp:Policy>
        </jaxws:features>
    </jaxws:endpoint>
</beans>

WSDL 文件

如果使用 WS-Policy 框架启用 WS-RM,您可以在 WSDL 文件中配置标准 WS-RM 策略属性。如果您希望服务互操作并使用 WS-RM 与部署到其他策略感知型 Web 服务堆栈的用户,最好采用这种方法。

例如,请参阅 “WS-Policy 框架:隐式添加拦截器”一节,其中在 WSDL 文件中配置了基本重新传输间隔。

外部附加

您可以在外部附加文件中配置标准 WS-RM 策略属性。如果您无法更改 WSDL 文件,这是个好方法。

例 21.7 “在外部附加中配置 WS-RM” 显示为特定 EPR 启用 WS-A 和 WS-RM(基本传输间隔为 30 秒)的外部附加。

例 21.7. 在外部附加中配置 WS-RM

<attachments xmlns:wsp="http://www.w3.org/2006/07/ws-policy" xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsp:PolicyAttachment>
        <wsp:AppliesTo>
           <wsa:EndpointReference>
                <wsa:Address>http://localhost:9020/SoapContext/GreeterPort</wsa:Address>
            </wsa:EndpointReference>
        </wsp:AppliesTo>
        <wsp:Policy>
            <wsam:Addressing xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata">
                <wsp:Policy/>
            </wsam:Addressing>
            <wsrmp:RMAssertion xmlns:wsrmp="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
                <wsrmp:BaseRetransmissionInterval Milliseconds="30000"/>
            </wsrmp:RMAssertion>
        </wsp:Policy>
    </wsp:PolicyAttachment>
</attachments>/

21.5.3. WS-RM 配置用例

概述

本小节着重介绍从用例的角度配置 WS-RM 属性。其中属性是一个标准的 WS-RM 策略属性(在 http://schemas.xmlsoap.org/ws/2005/02/rm/policy/ 命名空间中定义),只会显示在 rmManager Spring bean 中的 RMAsertion 中设置它的示例。有关如何在功能内设置这样的属性(如策略)的详情 ; 在 WSDL 文件中或外部附件中,请参阅 第 21.5.2 节 “配置标准 WS-RM 策略属性”

涵盖以下用例:

基本重新传输间隔

BaseRetransmissionInterval 元素指定在 RM 源重新传输了尚未确认的消息的时间间隔。它在 http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd 模式文件中定义。默认值为 3000 毫秒。

例 21.8 “设置 WS-RM Base Retransmission Interval” 显示如何设置 WS-RM 基本重新传输间隔。

例 21.8. 设置 WS-RM Base Retransmission Interval

<beans xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy
...>
<wsrm-mgr:rmManager id="org.apache.cxf.ws.rm.RMManager">
    <wsrm-policy:RMAssertion>
        <wsrm-policy:BaseRetransmissionInterval Milliseconds="4000"/>
    </wsrm-policy:RMAssertion>
</wsrm-mgr:rmManager>
</beans>

重新传输的 backoff

ExponentialBackoff 元素确定是否以指数级间隔执行对未确认消息的连续性重新传输尝试。

ExponentialBackoff 元素将启用此功能。默认情况下会使用 2 的 exponential backoff 比例。ExponentialBackoff 是一个标志。当元素存在时,会启用 exponential backoff。当元素不存在时,会禁用 exponential backoff。不需要值。

例 21.9 “设置 WS-RM Exponential Backoff Property” 演示了如何为重新传输设置 WS-RM exponential backoff。

例 21.9. 设置 WS-RM Exponential Backoff Property

<beans xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy
...>
<wsrm-mgr:rmManager id="org.apache.cxf.ws.rm.RMManager">
    <wsrm-policy:RMAssertion>
        <wsrm-policy:ExponentialBackoff/>
    </wsrm-policy:RMAssertion>
</wsrm-mgr:rmManager>
</beans>

确认的时间间隔

AcknowledgementInterval 元素指定 WS-RM 目标发送异步确认的时间间隔。除了同步确认外,还需要接收传入的消息。默认的异步确认间隔为 0 毫秒。这意味着,如果 AcknowledgementInterval 没有配置为特定值,确认将立即发送(即首次可用的商机)。

只有在满足以下条件时,RM 目的地才会发送异步确认:

  • RM 目的地使用非匿名 wsrm:acksTo 端点。
  • 在确认间隔到期前不会发生对响应消息的确认机会。

例 21.10 “设置 WS-RM Acknowledgement Interval” 显示如何设置 WS-RM 确认间隔。

例 21.10. 设置 WS-RM Acknowledgement Interval

<beans xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy
...>
<wsrm-mgr:rmManager id="org.apache.cxf.ws.rm.RMManager">
    <wsrm-policy:RMAssertion>
        <wsrm-policy:AcknowledgementInterval Milliseconds="2000"/>
    </wsrm-policy:RMAssertion>
</wsrm-mgr:rmManager>
</beans>

最大未确认的消息阈值

maxUnacknowledged 属性设置在序列被终止前每个序列的最大未确认消息数。

例 21.11 “设置 WS-RM Maximum Unacknowledged Message Threshold” 展示如何设置 WS-RM 的最大消息阈值。

例 21.11. 设置 WS-RM Maximum Unacknowledged Message Threshold

<beans xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager
...>
<wsrm-mgr:reliableMessaging>
    <wsrm-mgr:sourcePolicy>
        <wsrm-mgr:sequenceTerminationPolicy maxUnacknowledged="20" />
    </wsrm-mgr:sourcePolicy>
</wsrm-mgr:reliableMessaging>
</beans>

RM 序列的最大长度

maxLength 属性设置 WS-RM 序列的最大长度。默认值为 0, 这表示 WS-RM 序列的长度未绑定。

当设置此属性时,RM 端点会在达到限制时创建一个新的 RM 序列,并在收到之前发送的消息的所有确认后。使用 newsequence 发送新消息。

例 21.12 “设置 WS-RM 消息序列的最大长度” 演示了如何设置 RM 序列的最大长度。

例 21.12. 设置 WS-RM 消息序列的最大长度

<beans xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager
...>
<wsrm-mgr:reliableMessaging>
    <wsrm-mgr:sourcePolicy>
        <wsrm-mgr:sequenceTerminationPolicy maxLength="100" />
    </wsrm-mgr:sourcePolicy>
</wsrm-mgr:reliableMessaging>
</beans>

消息发送保障策略

您可以将 RM 目的地配置为使用以下发送保证策略:

  • AtMostOnce - RM 目标仅向应用程序目的地发送消息一次。如果发生错误后传送的信息超过。序列中的一些消息可能无法发送。
  • AtLeastOnce - RM 目的地至少向应用目的地发送消息。发送的每个消息都会被发送,否则将引发错误。有些信息可能会多次传送。
  • InOrder - RM 目标以发送顺序向应用程序目的地发送消息。这种交付保证可与 AtMostOnceAtLeastOnce 保障相结合。

例 21.13 “设置 WS-RM Message Delivery Assurance 策略” 展示如何设置 WS-RM 消息发送保证。

例 21.13. 设置 WS-RM Message Delivery Assurance 策略

<beans xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager
...>
<wsrm-mgr:reliableMessaging>
    <wsrm-mgr:deliveryAssurance>
        <wsrm-mgr:AtLeastOnce />
    </wsrm-mgr:deliveryAssurance>
</wsrm-mgr:reliableMessaging>
</beans>