【问题标题】:Converting Mule 1.3 "model" element to Mule 3 equivalent将 Mule 1.3“模型”元素转换为 Mule 3 等效项
【发布时间】:2012-05-31 02:22:33
【问题描述】:

我正在将 Mule 1.3 应用程序升级到 Mule 3.2.1(最新版本)。 Mule 1.3 配置文件有一个“model”元素和许多“mule-descriptor”子元素。

<model name="theModel">
  <mule-descriptor name="theName" implementation="com.company.SomeClass">
    <inbound-router>
      <endpoint address="servlet://service/foo" transformers="ACustomTransformer" responseTransformers="AnotherCustomTransformer" />
      <endpoint address="vm://anEndpoint"/>
    </inbound-router>
    <outbound-router>
      <router className="org.mule.routing.outbound.FilteringOutboundRouter">
        <endpoint address="Authenticator">
          <properties>
            <property name="propName" value="propValue" />
          </properties>
        </endpoint>
        <filter expression="/data = null" className="org.mule.routing.filters.xml.JXPathFilter" />
      </router>
      <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
        <endpoint address="RequestValidator" />
      </router>
    </outbound-router>
    <properties>
      <property name="someProp" value="someValue" />
    </properties>
  </mule-descriptor>
  <!-- more <mule-descriptor> elements -->
</model>

如何将其转换为与其对应的 Mule 3?谢谢。


编辑 - 2012 年 5 月 29 日

1) 一些 mule 描述符具有指向自身的入站路由器。

<mule-descriptor name="theName" implementation="com.company.SomeClass">
  <inbound-router>
    <endpoint address="theName" />
  </inbound-router>
</mule-descriptor> 

这些应该如何转换为 Mule 3 流?当我使用您的答案中的信息将这些转换为流时,我在启动时收到一条错误消息,这似乎表明它无法引用流,因为它仍在创建中(如循环依赖):

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ref:RequestValidator.20': Cannot resolve reference to bean 'RequestValidator' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'RequestValidator': Cannot create inner bean '(inner bean)' of type [org.mule.config.spring.factories.InboundEndpointFactoryBean] while setting bean property 'messageSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': 1 constructor arguments specified but no matching constructor found in bean '(inner bean)' (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)

2) 一个 mule 描述符使用来自 Mule API 的 BridgeComponent 类作为其实现。这些应该如何处理? Mule 3 中不存在此类。

<mule-descriptor name="theName" implementation="org.mule.components.simple.BridgeComponent">
  <inbound-router>
    <endpoint address="vm://theInboundAddress" />
  </inbound-router>
  <outbound-router>
    <router className="org.mule.routing.outbound.FilteringOutboundRouter">
      <endpoint address="vm://theOutboundAddress" />
    </router>
  </outbound-router>
</mule-descriptor>

3) 另一个 mule 描述符在其 &lt;outbound-router&gt; 元素中有一个“matchAll”属性。这应该如何转换为 Mule 3 流?

<mule-descriptor name="theName" implementation="com.company.SomeClass">
  <inbound-router>
    <endpoint address="servlet://theInboundEndpoint" />
  </inbound-router>
  <outbound-router matchAll="true">
    <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
      <endpoint address="firstOutboundEndpoint" />
    </router>
    <router className="org.mule.routing.outbound.FilteringOutboundRouter" transformer="MyTransformer">
      <endpoint address="vm://secondOutboundEndpoint" />
      <filter pattern="Error*" className="org.mule.routing.filters.WildcardFilter" />
    </router>
  </outbound-router>
</mule-descriptor>

4) Mule 1.x 配置有一些&lt;endpoint-identifier&gt; 元素的名称与某些&lt;mule-descriptor&gt; 元素的名称相同。这些名称也用作&lt;mule-descriptor&gt; 中的端点地址。例如:

<endpoint-identifiers>
  <endpoint-identifier name="TheEndpointName" value="vm://theEndpointAddress" />
</endpoint-identifiers>

...

<model name="...">
  <mule-descriptor name="TheEndpointName" implementation="...">
    <inbound-router>
      <endpoint address="TheEndpointName" />
    </inbound-router>
    ...
  </mule-descriptor>
  ...
</model>

我的猜测是 Mule 3 等效项应该类似于下面的代码。这是正确的吗?

<flow name="TheEndpointName">
  <!--
    My first guess was:
    <inbound-endpoint ref="TheEndpointName" />
  -->
  <vm:inbound-endpoint path="theEndpointAddress" />
  ...
</flow>

再次感谢您。

2012 年 5 月 30 日编辑

5) 一些 mule 描述符使用 Mule API 中的 RestServiceWrapper 类。当我将其转换为 Mule 3 &lt;flow&gt; 时,出现此错误:

The required object/property 'serviceUrl' is null

我注意到 Mule 1.x 配置中的 mule-descriptor 设置了一个名为“urlFromMessage”的属性,这似乎是说,而不是在 XML 配置文件中提供 URL,它将作为属性提供到骡子消息。但是,“urlFromMessage”属性在 Mule 3 的 RestServiceWrapper 类版本中不存在。我应该在 Mule 3 中使用不同的组件类吗?由于这个类是 Mule API 的一部分,有没有我应该使用的标准 XML 标签?谢谢。

<mule-descriptor name="theName" implementation="org.mule.components.rest.RestServiceWrapper">
  <inbound-router>
    ...
  </inbound-router>
  <properties>
    <property name="urlFromMessage" value="true" />
  </properties>
</mule-descriptor>

【问题讨论】:

    标签: mule


    【解决方案1】:
    • model 已被弃用。
    • flow 已替换 mule-descriptor

    还有更多,请查看为 Mule 3 转换的配置:

    <flow name="theName">
        <composite-source>
            <vm:inbound-endpoint path="anEndpoint">
                <transformer ref="ACustomTransformer" />
                <response>
                    <transformer ref="AnotherCustomTransformer" />
                </response>
            </vm:inbound-endpoint>
            <servlet:inbound-endpoint path="/service/foo" />
        </composite-source>
        <component>
            <singleton-object class="com.company.SomeClass">
                <property key="someProp" value="someValue" />
            </singleton-object>
        </component>
        <outbound-endpoint ref="Authenticator">
            <expression-filter expression="/data = null"
                evaluator="jxpath" />
            <property key="propName" value="propValue" />
        </outbound-endpoint>
        <outbound-endpoint ref="RequestValidator" />
    </flow>
    

    注意:此配置适用于 Mule 3.2.1,但我不能保证它完全符合您的要求,您必须对其进行测试和调整!

    更多答案:

    1) 为流和端点使用不同的名称,它们现在在后台注册为单独的 bean,因此不能共享相同的名称。这给出了:

    <flow name="theFlowName">
        <inbound-endpoint ref="theInboundName" />
        <component>
            <singleton-object class="com.company.SomeClass" />
        </component>
    </flow>
    

    2) 使用Bridge pattern:

    <pattern:bridge name="theName"
                    inboundAddress="vm://theInboundAddress"
                    outboundAddress="vm://theOutboundAddress" />
    

    3) 使用all routing message processorprocessor-chain 将多个消息处理器组合为一个:

    <flow name="theName">
        <servlet:inbound-endpoint path="/theInboundEndpoint" />
        <component>
            <singleton-object class="com.company.SomeClass" />
        </component>
        <all>
            <outbound-endpoint ref="firstOutboundEndpoint" />
            <processor-chain>
                <transformer ref="MyTransformer" />
                <wildcard-filter pattern="Error*" />
                <vm:outbound-endpoint path="secondOutboundEndpoint" />
            </processor-chain>
        </all>
    </flow>
    

    4) 您不能在流中声明全局端点,并且您需要为端点和流使用不同的名称,因此实际的 Mule 3 配置等效项是:

    <vm:endpoint name="TheEndpointName" path="theEndpointAddress" />
    
    <flow name="TheFlowName">
        <inbound-endpoint ref="TheEndpointName" />
        <component>
            <singleton-object class="..." />
        </component>
    </flow>
    

    5) 大多数 Mule 默认组件现在都可以作为 XML 元素使用,因此您确实需要使用:

    <http:rest-service-component serviceUrl="..." />
    

    urlFromMessage 消失了:您可以使用Mule expression 以动态方式从发送消息中提取 URL。例如,如果 URL 在名为 svcURL 的入站属性中提供,请使用:

    <http:rest-service-component serviceUrl="#[header:INBOUND:svcURL]" />
    

    【讨论】:

    • 嗨,大卫,感谢您的帮助。我仍在研究 mule 描述符,毫无疑问很快会有更多问题......
    • 您介意接受这个并在转换过程中提出新问题吗?顺便说一句,祝你好运!
    • David 我还不想接受,我还没有尝试运行我的 Mule 应用程序。
    • 嗨,大卫,如果您有时间,我会用一些后续问题编辑这个问题。我没有创建新问题,因为这些问题仍然与转换 &lt;mule-descriptor&gt; 元素有关。
    • 请注意,从 1.x 配置中,我不确定某些端点是对现有端点的引用还是在本地使用 URL 声明(区别不清楚)。这就是为什么我混合使用 ref 和 URI 并传输特定端点来向您展示选项的调色板。您可能必须将它们整理出来并选择适用于您的情况的那些。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    相关资源
    最近更新 更多