【问题标题】:Mule: Interface binding for different components, how to avoid duplication?Mule:不同组件的接口绑定,如何避免重复?
【发布时间】:2017-07-03 11:14:32
【问题描述】:

我们有以下骡流程:

<flow name="mule-flow-1">
   <component>
       <spring-object bean="springBean_1"/>
        <binding interface="com.acme.EmailService" method="send">
             <vm:outbound-endpoint path="send-email" exchange-pattern="one-way"/>
        </binding>
     </component> 
</flow>

但是现在我们想引入新的流程,新的 Spring bean 使用相同的 EmailService.send 方法,所以,我们可以这样做:

<flow name="mule-flow-2">
   <component>
       <spring-object bean="springBean_2"/>
        <binding interface="com.acme.EmailService" method="send">
             <vm:outbound-endpoint path="send-email" exchange-pattern="one-way"/>
        </binding>
     </component> 
</flow>

如您所见,我们在两个不同的流程中绑定了两次EmailService.send 方法,这是纯代码重复。

是否可以将EmailService.send 方法绑定到一个共同的地方,只在mule-flow-1mule-flow-2 中使用ref?

【问题讨论】:

    标签: java spring mule esb


    【解决方案1】:

    也许你可以使用子流?在那里定义您的组件,然后在您想要重用它的任何流程中使用 flow-ref。

    <sub-flow name="mule-flow-send">
     <component>
       <spring-object bean="springBean_1"/>
        <binding interface="com.acme.EmailService" method="send">
             <vm:outbound-endpoint path="send-email" exchange-pattern="one-way"/>
        </binding>
     </component> 
    </sub-flow>
    

    然后重复使用:

    <flow name="mule-flow-1">
      <flow-ref name="mule-flow-send" doc:name="mule-flow-send"/>
    </flow>
    <flow name="mule-flow-2">
      <flow-ref name="mule-flow-send" doc:name="mule-flow-send"/>
    </flow>
    

    【讨论】:

    • 问题是:我们使用的是springBean_1springBean_2,它们都使用EmailService接口的相同方法send,所以你的解决方案略有错误。
    猜你喜欢
    • 1970-01-01
    • 2018-05-27
    • 2015-09-15
    • 2020-10-25
    • 1970-01-01
    • 2016-09-06
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多