Mais conteúdo relacionado Semelhante a Message enricher in mule (20) Message enricher in mule2. *One common scenario involves the need to enrich an
incoming message with information that isn’t provided by
the source system
*Mule currently supports enrichment of flow variables and
message headers only.
*The “enrichment resource” can be any message
processor, outbound connector, processor-chain or
flow-ref.
*By having inline enrich tags for multiple targets
3. * <?xml version="1.0" encoding="UTF-8"?>
* <mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
* xmlns:spring="http://www.springframework.org/schema/beans"
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
* xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-curre
* http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
* http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
* http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
* http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
* http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
* http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
* <http:listener-config name="HTTP_Listener_8124" host="localhost" port="8124" doc:name="HTTP Listener Configuration"/>
* <data-mapper:config name="XML_To_XML" transformationGraphPath="xml_to_xml.grf" doc:name="XML_To_XML"/>
* <http:request-config name="HTTP_Request_Configuration" host="localhost" port="8124" doc:name="HTTP Request Configuration"/>
* <flow name="encricherFlow">
* <http:listener config-ref="HTTP_Listener_8124" path="/enricher" doc:name="HTTP"/>
* <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
* <enricher doc:name="Message Enricher">
* <flow-ref name="assign_state_using_zip" doc:name="get state variable"/>
* <enrich target="#[sessionvariable:newState]" source="#[xpath://enrichedPayload/state]"/>
* <!-- <enrich target="#[variable:newState]" source="#[xpath://enrichedPayload/state]"/> -->
* <enrich target="#[variable:country]" source="#[xpath://enrichedPayload/country']"/>
* </enricher>
*
4. * <logger doc:name="Logger"/>
* <data-mapper:transform config-ref="XML_To_XML" doc:name="XML To XML">
* <data-mapper:input-arguments>
* <data-mapper:input-argument key="CountryCode">#[flowVars.country]</data-mapper:input-argument>
* <data-mapper:input-argument key="State">#[sessionVars.newState]</data-mapper:input-argument>
* </data-mapper:input-arguments>
* </data-mapper:transform>
* </flow>
* <sub-flow name="assign_state_using_zip">
* <expression-component doc:name="Andhra"><![CDATA[String response="<enrichedPayload>";
* if( xpath3("//address/zip").equals("518001")){
* response += "<state>AP</state>";
* }
* else if(xpath3("//address/zip").equals("500001")){
* response += "<state>TS</state>";
* }
* else{
* response += "<state>INVALID STATE</state>";
* }
* if( xpath3("//address/country").equalsIgnoreCase("INDIA")){
* response += "<country>+91</country>";
* }
* else if(xpath3("//address/country").equalsIgnoreCase("UK")){
* response += "<state>+44</state>";
* }
* else{
* response += "<state>INVALID Country</state>";
* }
* response += "</enrichedPayload>";
*
5. * payload = response;
* System.out.println("Enriched Payload is::"+payload);]]></expression-component>
* </sub-flow>
* <flow name="complexencricherFlow">
* <http:listener config-ref="HTTP_Listener_8124" path="/complexenricher" doc:name="HTTP"/>
* <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
* <enricher doc:name="Message Enricher" target="#[flowVars.state]" source="#[xpath2://address/state]">
* <processor-chain doc:name="Processor Chain">
* <http:request config-ref="HTTP_Request_Configuration" path="/state" method="POST" doc:name="HTTP"/>
* <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
* </processor-chain>
* </enricher>
* <data-mapper:transform config-ref="XML_To_XML" doc:name="XML To XML">
* <data-mapper:input-arguments>
* <data-mapper:input-argument key="State">#[flowVars.state]</data-mapper:input-argument>
* </data-mapper:input-arguments>
* </data-mapper:transform>
* </flow>
*
6. * <flow name="muleencricherFlow">
* <http:listener config-ref="HTTP_Listener_8124" path="/state" doc:name="HTTP"/>
* <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
* <expression-transformer doc:name="Expression">
* <return-argument evaluator="xpath2" expression="/address/zip"/>
* </expression-transformer>
* <choice doc:name="evaluate zip and assingn a state">
* <when expression="#[payload =='518001']">
* <set-payload value="<address><state>AP</state></address>" doc:name="Set Payload"/>
* </when>
* <when expression="#[payload =='500043']">
* <set-payload value="<address><state>TS</state></address>" doc:name="Set Payload"/>
* </when>
* <otherwise>
* <set-payload value="<address><state>Andhra</state></address>" doc:name="Set Payload"/>
* </otherwise>
* </choice>
* </flow>
* </mule>