Invoking a sub-flow
from code is no small feat but possible.
Here is a test component that does invoke a sub-flow
injected in it:
public class TestComponent implements MuleContextAware, FlowConstructAware
{
private MuleContext muleContext;
private FlowConstruct flowConstruct;
private MessageProcessor subFlow;
public void initialize() throws MuleException
{
muleContext.getRegistry().applyProcessorsAndLifecycle(subFlow);
}
public String test(final String requestMessage) throws Exception
{
final MuleEvent muleEvent = new DefaultMuleEvent(new DefaultMuleMessage(requestMessage, muleContext),
MessageExchangePattern.REQUEST_RESPONSE, flowConstruct);
final MuleEvent resultEvent = subFlow.process(muleEvent);
return resultEvent.getMessageAsString();
}
public void setMuleContext(final MuleContext muleContext)
{
this.muleContext = muleContext;
}
public void setFlowConstruct(final FlowConstruct flowConstruct)
{
this.flowConstruct = flowConstruct;
}
public void setSubFlow(final MessageProcessor subFlow)
{
this.subFlow = subFlow;
}
}
The component is configured this way:
<spring:beans>
<spring:bean name="testComponent" class="com.example.TestComponent"
p:subFlow-ref="testSubFlow" init-method="initialize" />
</spring:beans>
...
<component>
<spring-object bean="testComponent" />
</component>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…