Mule:不同组件的接口绑定,如何避免重复



我们有以下骡子流:

<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>

但是现在我们想引入新的流程,使用新的春豆,它使用相同的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

也许你可以使用子流?在那里定义您的组件,然后在要重用它的任何流中使用 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>

最新更新