Mule 3: Controlling whether a flow is allowed to be executed

眉间皱痕 提交于 2019-11-29 15:10:38

问题


My current situation:

I currently have a Mule ESB application with three flows which process messages originating from two different sources, these three flows are tied together using a VM queue.

Flow #1:

Inbound (Endpoint #1) -> (Perform message processing and transformations) -> Outbound (Endpoint #3)

Flow #2:

Inbound (Endpoint #2) -> (Perform message processing and transformations) -> Outbound (Endpoint #3)

Flow #3

Inbound (Endpoint #3) -> (Perform message processing and transformations, do stuff) -> Outbound

Problem/ Issue:

Now what I want to do is introduce a fourth flow, Flow #4, that gets state information from an inbound endpoint and based off this information be able to prevent Flow #3 from ever being executed/ prevent it from processing its inbound messages.

In other words, what I'd ideally like is to have Flow #4 run at the startup of the ESB application (like all flows seem to automatically do), and based on the state information it gets from its inbound message, prevent/ allow or enable/ disable Flow #3 from ever processing messages from Endpoint #3.

The following are what I ideally require:

Requirements:

  1. Must be able to accomplish solely through the mule flow XML, no additional POJO/ custom Java objects.
  2. Flow #4 must be performed at startup of the ESB application and only the first inbound message needs to ever be processed.
  3. Ideally, I don't want Flow #3 to have a composite inbound source or have to evaluate every inbound message the state of some global variable.

What's the best way to accomplish what I want to do?

If there is no real good solution, then if I must omit #3 requirement, then what's the best way to accomplish such a global variable that is shared between two independent flows that aren't tied together by some outbound -> inbound endpoint in the XML config? I've tried using session properties, but they require that the flows be tied together as either subflows or by an endpoint.

Thanks.


回答1:


Use a global property and a few MEL expressions to make this happen:

<global-property name="gate_open" value="true" />

<flow name="gated-flow">
    <vm:inbound-endpoint path="gated.in" />
    <expression-filter expression="#[app.registry.gate_open]" />
    ...
</flow>


<flow name="gate-controller">
    <vm:inbound-endpoint path="gate.in"  />
    <expression-component>
      app.registry.gate_open = false
    </expression-component>
</flow>

Sending any message to vm://gate.in will close the gate and gated-flow will stop processing the messages it receives.

You can use any protocol you want instead of VM.



来源:https://stackoverflow.com/questions/11885181/mule-3-controlling-whether-a-flow-is-allowed-to-be-executed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!