Tuesday, May 12, 2009

Mule2.x - expression-recipient-list-router – Dynamic Endpoint in mule

Mule2.x - expression-recipient-list-router – Dynamic Endpoint in mule

The expression recipient list router can be used to send the same message to multiple endpoints over the same endpoint or to implement routing-slip behavior where the next destination for the message is determined from message properties or the payload. It uses a list of recipient’s endpoints which are extracted from the message using an expression.

Here I will give you an example how to use the expression-recipient-list-router.

In this example I am using mule 2.2. (http://www.mulesource.org)


Mule-config.xml

Spring declaration
<spring:bean id="ExpressionHandlerBean"
class="com.javatch.expression.ExpressionHandlerBean">

actual mule configuration
<model name="test Expression">
<service name="Expression">
<inbound>
<vm:inbound-endpoint address="vm://Expression" synchronous="true" >
</vm:inbound-endpoint>
</inbound>
<component>
<spring-object bean="ExpressionHandlerBean"></spring-object>
</component>
<outbound>
<expression-recipient-list-router evaluator="header"
expression="ADDR_LIST" >
</expression-recipient-list-router>
</outbound>
</service>

<service name="TEST">
<inbound>
<vm:inbound-endpoint address="vm://TEST" synchronous="true" />
</inbound>
<outbound>
<pass-through-router>
<file:outbound-endpoint path="${some temp dir}"
transformer-refs="ValidateTheFlow" />
</pass-through-router>
</outbound>
</service>
</model>





In the component class I am adding the endpoint, here if you can any number endpoint ExpressionRecipientList.java (from Mule) will take care of functional flow. 

ExpressionHandlerBean.java

public class ExpressionHandlerBean implements Callable {

public Object onCall(MuleEventContext eventContext) throws Exception {
try {
List<String> addressList = new ArrayList<String>();
addressList.add("vm://TEST");
eventContext.getMessage().setProperty("ADDR_LIST",addressList);
}
catch( Exception ex ) {
ex.printStackTrace();
}
return null;
}

}

3 comments:

Anonymous said...

in the component instead of returning null you should return eventContext object

Jaskirat said...

in the component instead of returning null you should return eventContext object

Forgot to add my name in last comment.

Good post btw.

Anonymous said...

top [url=http://www.c-online-casino.co.uk/]online casinos[/url] brake the latest [url=http://www.realcazinoz.com/]casino[/url] autonomous no deposit reward at the foremost [url=http://www.baywatchcasino.com/]bay attend casino
[/url].