Created
September 18, 2012 21:54
-
-
Save havana59er/3746169 to your computer and use it in GitHub Desktop.
Mule - Enterprise Integration Pattern - Routing Slip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<mule version="EE-3.3.1" | |
xmlns="http://www.mulesoft.org/schema/mule/core" | |
xmlns:vm="http://www.mulesoft.org/schema/mule/vm" | |
xmlns:spring="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation=" | |
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd | |
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> | |
<!-- Routing Slip Pattern --> | |
<flow name="RoutingSlipFlow"> | |
<inbound-endpoint exchange-pattern="request-response" address="vm://RoutingSlip" /> | |
<set-variable variableName="routingSlip" value="#[message.inboundProperties.routingSlip]" /> | |
<foreach collection="#[flowVars.routingSlip]"> | |
<expression-component>flowVars.currentEndpoint = message.payload; message.payload = flowVars.rootMessage.payload</expression-component> | |
<vm:outbound-endpoint exchange-pattern="request-response" path="#[flowVars.currentEndpoint]" /> | |
<expression-component>flowVars.rootMessage.payload = message.payload</expression-component> | |
</foreach> | |
</flow> | |
<!-- Test Endpoints --> | |
<flow name="flow1"> | |
<inbound-endpoint exchange-pattern="request-response" address="vm://flow1" /> | |
<set-payload value="#[message.payload + 'flow1;']" /> | |
</flow> | |
<flow name="flow2"> | |
<inbound-endpoint exchange-pattern="request-response" address="vm://flow2" /> | |
<set-payload value="#[message.payload + 'flow2;']" /> | |
</flow> | |
<flow name="flow3"> | |
<inbound-endpoint exchange-pattern="request-response" address="vm://flow3" /> | |
<set-payload value="#[message.payload + 'flow3;']" /> | |
</flow> | |
<flow name="flow4"> | |
<inbound-endpoint exchange-pattern="request-response" address="vm://flow4" /> | |
<set-payload value="#[message.payload + 'flow4;']" /> | |
</flow> | |
<flow name="flow5"> | |
<inbound-endpoint exchange-pattern="request-response" address="vm://flow5" /> | |
<set-payload value="#[message.payload + 'flow5;']" /> | |
</flow> | |
<!-- Test Harness Endpoint --> | |
<flow name="ExampleRoutingSlipFlow"> | |
<inbound-endpoint exchange-pattern="request-response" address="vm://TriggerRoutingSlipTest" /> | |
<set-payload value="Executed Endpoints:" /> | |
<set-property propertyName="routingSlip" value="#[{'flow5','flow2','flow3'}]" /> | |
<outbound-endpoint exchange-pattern="request-response" address="vm://RoutingSlip" /> | |
</flow> | |
</mule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.junit.Test; | |
import org.mule.api.MuleMessage; | |
import org.mule.api.client.MuleClient; | |
import org.mule.tck.junit4.FunctionalTestCase; | |
public class RoutingSlipTest extends FunctionalTestCase { | |
@Test | |
public void testRoutingSlip() throws Exception { | |
MuleClient client = muleContext.getClient(); | |
Map<String, Object> props = new HashMap<String, Object>(1); | |
props.put("routingSlip", new String[] {"flow5", "flow2", "flow3"}); | |
MuleMessage resp = client.send("vm://RoutingSlip", "Executed Endpoints: ", props); | |
String expectedPayload = "Executed Endpoints: flow5;flow2;flow3;"; | |
assertTrue("Payload is not of type String", | |
resp.getPayload() instanceof String); | |
String actualPayload = resp.getPayloadAsString(); | |
assertTrue(String.format("Payload does not match expected value. Actual: %s Expected: %s", actualPayload, expectedPayload), | |
actualPayload.equalsIgnoreCase(expectedPayload)); | |
} | |
@Override | |
protected String getConfigResources() { | |
return "src/main/app/routingslip.xml"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment