我们有以下骡子流:
<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-1
和mule-flow-2
中使用参考?
答案 0 :(得分:0)
也许你可以使用子流?在那里定义组件,然后在要重用它的任何流程中使用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>