The following example is on the usage of the expression-recipient-list-router. This router can be used to extract the endpoints from the message and route it to the corresponding component.
Java Classes:
CreateXmlMessageComponent:
DisplayMessageComponent:
ComputeMsgComponent:
mule-config.xml:
Java Classes:
CreateXmlMessageComponent:
package com.expressrecipienttransformers; public class CreateXmlMessageComponent { public String createMessage(String msg) { StringBuilder sb = new StringBuilder(); sb.append("<message>"); sb.append("<recipientList>"); sb.append("<recipient>vm://display-message-channel</recipient>"); sb.append("<recipient>vm://compute-message-channel</recipient>"); sb.append("</recipientList>"); sb.append("<info>"); sb.append("Hi there"); sb.append("</info>"); sb.append("</message>"); return sb.toString(); } }
DisplayMessageComponent:
package com.expressrecipienttransformers; public class DisplayMessageComponent { public void displayMessage(String msg) { System.out.println("Into displaymessage"); System.out.println(msg); } }
ComputeMsgComponent:
package com.expressrecipienttransformers; public class ComputeMsgComponent { public void compute(String msg) { System.out.println("Into compute component"); System.out.println(msg.length()); } }
mule-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
xsi:schemaLocation="
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">
<stdio:connector name="stdioIN" promptMessage="Press any key to continue" />
<model name="expression-recipient-list-model">
<service name="expression-recipient-list-serviec">
<inbound>
<stdio:inbound-endpoint
connector-ref="stdioIN" system="IN" />
</inbound>
<component
class="com.expressrecipienttransformers.CreateXmlMessageComponent"></component>
<outbound>
<expression-recipient-list-router
expression="/message/recipientList/recipient"
evaluator="xpath" />
</outbound>
</service>
<service name="DisplayService">
<inbound>
<vm:inbound-endpoint path="display-message-channel" />
</inbound>
<component
class="com.expressrecipienttransformers.DisplayMessageComponent" />
</service>
<service name="ComputeService">
<inbound>
<vm:inbound-endpoint path="compute-message-channel" />
</inbound>
<component
class="com.expressrecipienttransformers.ComputeMsgComponent" />
</service>
</model>
</mule
No comments:
Post a Comment