[CONF] Apache Camel Content Enricher
Claus Ibsen edited the page: Content Enricher ... Camel supports the Content Enricher from the EIP patterns using a Message Translator, an arbitrary Processor in the routing logic, or using the enrich DSL element to enrich the message. ... You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery, and then send it on to another destination. For example using InOnly (one way messaging) Code Block from(activemq:My.Queue). to(velocity:com/acme/MyResponse.vm). to(activemq:Another.Queue); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this: Code Block from(activemq:My.Queue). to(velocity:com/acme/MyResponse.vm); ... Finally we can use Bean Integration to use any Java method on any bean to act as the transformer Code Block from(activemq:My.Queue). beanRef(myBeanName, myMethodName). to(activemq:Another.Queue); ... Using Spring XML Code Block
[CONF] Apache Camel Content Enricher
Content Enricher Page edited by Claus Ibsen Changes (1) ... {{pollEnrich}} on the other hand uses a [Polling Consumer] to obtain the additional data. It is usually used for [Event Message] messaging, for instance to read a file or download a [FTP|FTP2] file. {warning:title=Data from current Exchange not used} {{pollEnrich}} or {{enrich}} does *not* access any data from the current [Exchange] which means when polling it cannot use any of the existing headers you may have set on the [Exchange]. For example you cannot set a filename in the {{Exchange.FILE_NAME}} header and use {{pollEnrich}} to consume only that file. For that you *must* set the filename in the endpoint URI. Instead of using {{enrich}} you can use [Recipient List] and have dynamic endpoints and define an {{AggregationStrategy}} on the [Recipient List] which then would work as a {{enrich}} would do. {warning} h3. Enrich Options ... Full Content Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an arbitrary Processor in the routing logic, or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery, and then send it on to another destination. For example using InOnly (one way messaging) from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this: from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); Here is a simple example using the DSL directly to transform the message body In this example we add our own Processor using explicit Java code Finally we can use Bean Integration to use any Java method on any bean to act as the transformer from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); For further examples of this pattern in use you could look at one of the JUnit tests TransformTest TransformViaDSLTest Using Spring XML route from uri="activemq:Input"/ bean ref="myBeanName" method="doTransform"/ to uri="activemq:Output"/ /route Content enrichment using the enrich DSL element Camel comes with two flavors of content enricher in the DSL enrich pollEnrich enrich uses a Producer to obtain the additional data. It is usually used for Request Reply messaging, for instance to invoke an external web service. pollEnrich on the other hand uses a Polling Consumer to obtain the additional data. It is usually used for Event Message messaging, for instance to read a file or download a FTP file. Data from current Exchange not usedpollEnrich or enrich does not access any data from the current Exchange which means when polling it cannot use any of the existing headers you may have set on the Exchange. For example you cannot set a filename in the Exchange.FILE_NAME header and use pollEnrich to consume only that file. For that you must set the filename in the endpoint URI. Instead of using enrich you can use Recipient List and have dynamic endpoints and define an AggregationStrategy on the Recipient List which then would work as a enrich would do. Enrich Options Name Default Value Description uri The endpoint uri for the external service to enrich from. You must use either uri or ref. ref Refers to the endpoint for the external service to enrich from. You must use either uri or ref. strategyRef Refers to an AggregationStrategy to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. From Camel 2.12 onwards you can also use a POJO as the AggregationStrategy, see the Aggregate page for more details. strategyMethodName Camel 2.12: This option can be used to explicit declare the method name to use, when using POJOs as the AggregationStrategy. See the Aggregate page for more details. strategyMethodAllowNull false Camel 2.12: If this option is false then the aggregate method is not used if there was no data to enrich. If this option is true then null values is used as the oldExchange (when no data to enrich), when using POJOs as the AggregationStrategy. See the Aggregate page for more details. Using the Fluent Builders AggregationStrategy aggregationStrategy = ... from("direct:start") .enrich("direct:resource",
[CONF] Apache Camel Content Enricher
Content Enricher Page edited by Claus Ibsen Changes (4) ... | {{uri}} | | The endpoint uri for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{ref}} | | Refers to the endpoint for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. From *Camel 2.12* onwards you can also use a POJO as the {{AggregationStrategy}}, see the [Aggregate|Aggregator2] page for more details. | | {{strategyMethodName}} | | *Camel 2.12:* This option can be used to explicit declare the method name to use, when using POJOs as the {{AggregationStrategy}}. See the [Aggregate|Aggregator2] page for more details. | {div} ... | {{uri}} | | The endpoint uri for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{ref}} | | Refers to the endpoint for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. From *Camel 2.12* onwards you can also use a POJO as the {{AggregationStrategy}}, see the [Aggregate|Aggregator2] page for more details. | | {{strategyMethodName}} | | *Camel 2.12:* This option can be used to explicit declare the method name to use, when using POJOs as the {{AggregationStrategy}}. See the [Aggregate|Aggregator2] page for more details. | | {{timeout}} | {{-1}} | Timeout in millis when polling from the external service. See below for important details about the timeout. | {div} ... Full Content Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an arbitrary Processor in the routing logic, or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery, and then send it on to another destination. For example using InOnly (one way messaging) from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this: from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); Here is a simple example using the DSL directly to transform the message body In this example we add our own Processor using explicit Java code Finally we can use Bean Integration to use any Java method on any bean to act as the transformer from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); For further examples of this pattern in use you could look at one of the JUnit tests TransformTest TransformViaDSLTest Using Spring XML route from uri="activemq:Input"/ bean ref="myBeanName" method="doTransform"/ to uri="activemq:Output"/ /route Content enrichment using the enrich DSL element Camel comes with two flavors of content enricher in the DSL enrich pollEnrich enrich uses a Producer to obtain the additional data. It is usually used for Request Reply messaging, for instance to invoke an external web service. pollEnrich on the other hand uses a Polling Consumer to obtain the additional data. It is usually used for Event Message messaging, for instance to read a file or download a FTP file. Enrich Options Name Default Value Description uri The endpoint uri for the external service to enrich from. You must use either uri or ref. ref Refers to the endpoint for the external service to enrich from. You must use either uri or ref. strategyRef Refers to an AggregationStrategy to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. From Camel 2.12 onwards you can also use a POJO as the
[CONF] Apache Camel Content Enricher
Content Enricher Page edited by Claus Ibsen Changes (2) ... | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. From *Camel 2.12* onwards you can also use a POJO as the {{AggregationStrategy}}, see the [Aggregate|Aggregator2] page for more details. | | {{strategyMethodName}} | | *Camel 2.12:* This option can be used to explicit declare the method name to use, when using POJOs as the {{AggregationStrategy}}. See the [Aggregate|Aggregator2] page for more details. | | {{strategyMethodAllowNull}} | {{false}} | *Camel 2.12:* If this option is {{false}} then the aggregate method is not used if there was no data to enrich. If this option is {{true}} then {{null}} values is used as the {{oldExchange}} (when no data to enrich), when using POJOs as the {{AggregationStrategy}}. See the [Aggregate|Aggregator2] page for more details. | {div} ... | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. From *Camel 2.12* onwards you can also use a POJO as the {{AggregationStrategy}}, see the [Aggregate|Aggregator2] page for more details. | | {{strategyMethodName}} | | *Camel 2.12:* This option can be used to explicit declare the method name to use, when using POJOs as the {{AggregationStrategy}}. See the [Aggregate|Aggregator2] page for more details. | | {{strategyMethodAllowNull}} | {{false}} | *Camel 2.12:* If this option is {{false}} then the aggregate method is not used if there was no data to enrich. If this option is {{true}} then {{null}} values is used as the {{oldExchange}} (when no data to enrich), when using POJOs as the {{AggregationStrategy}}. See the [Aggregate|Aggregator2] page for more details. | | {{timeout}} | {{-1}} | Timeout in millis when polling from the external service. See below for important details about the timeout. | {div} ... Full Content Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an arbitrary Processor in the routing logic, or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery, and then send it on to another destination. For example using InOnly (one way messaging) from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this: from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); Here is a simple example using the DSL directly to transform the message body In this example we add our own Processor using explicit Java code Finally we can use Bean Integration to use any Java method on any bean to act as the transformer from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); For further examples of this pattern in use you could look at one of the JUnit tests TransformTest TransformViaDSLTest Using Spring XML route from uri="activemq:Input"/ bean ref="myBeanName" method="doTransform"/ to uri="activemq:Output"/ /route Content enrichment using the enrich DSL element Camel comes with two flavors of content enricher in the DSL enrich pollEnrich enrich uses a Producer to obtain the additional data. It is usually used for Request Reply messaging, for instance to invoke an external web service. pollEnrich on the other hand uses a Polling Consumer to obtain the additional data. It is usually used for Event Message messaging, for instance to read a file or download a FTP file. Enrich Options Name Default Value Description uri The endpoint uri for the external service to enrich from. You must use either uri or ref. ref Refers to the endpoint for the external service to enrich from. You must use either uri or ref. strategyRef Refers to an AggregationStrategy to
[CONF] Apache Camel Content Enricher
Content Enricher Page edited by Claus Ibsen Changes (4) ... | {{ref}} | | Refers to the endpoint for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. | | {{timeout}} | {{0}} {{-1}} | Timeout in millis when polling from the external service. See below for important details about the timeout. | {div} {info:title=Good practice to use timeout value} By default Camel will use the {{receive}}. Which may block until there is a message available. It is therefore recommended to always provide a timeout value, to make this clear that we may wait for a message, until the timeout is hit. {info} By default Camel will use the {{receiveNoWait}}. If there is no data then the {{newExchange}} in the aggregation strategy is {{null}}. You can pass in a timeout value that determines which method to use - if timeout is -1 or other negative number then {{receive}} is selected (*Important:* the {{receive}} method may block if there is no message) - if timeout is 0 then {{receiveNoWait}} is selected - otherwise {{receive(timeout)}} is selected ... Full Content Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an arbitrary Processor in the routing logic, or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery, and then send it on to another destination. For example using InOnly (one way messaging) from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this: from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); Here is a simple example using the DSL directly to transform the message body from("direct:start").setBody(body().append(" World!")).to("mock:result"); In this example we add our own Processor using explicit Java code from("direct:start").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + " World!"); } }).to("mock:result"); Finally we can use Bean Integration to use any Java method on any bean to act as the transformer from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); For further examples of this pattern in use you could look at one of the JUnit tests TransformTest TransformViaDSLTest Using Spring XML route from uri="activemq:Input"/ bean ref="myBeanName" method="doTransform"/ to uri="activemq:Output"/ /route Content enrichment using the enrich DSL element Camel comes with two flavors of content enricher in the DSL enrich pollEnrich enrich uses a Producer to obtain the additional data. It is usually used for Request Reply messaging, for instance to invoke an external web service. pollEnrich on the other hand uses a Polling Consumer to obtain the additional data. It is usually used for Event Message messaging, for instance to read a file or download a FTP file. Enrich Options Name Default Value Description uri The endpoint uri for the external service to enrich from. You must use either uri or ref. ref Refers to the endpoint for the external service to enrich from. You must use either uri or ref. strategyRef Refers to an AggregationStrategy to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. Using the Fluent Builders AggregationStrategy aggregationStrategy = ... from("direct:start") .enrich("direct:resource", aggregationStrategy) .to("direct:result"); from("direct:resource") ... The content enricher (enrich) retrieves additional data from a resource endpoint in order to enrich an incoming message (contained in the original exchange). An aggregation strategy is used to combine the original exchange and the resource
[CONF] Apache Camel Content Enricher
Content Enricher Page edited by Glen Mazza Comment: Editorial cleanup Changes (16) h3. Content Enricher Camel supports the [Content Enricher|http://www.enterpriseintegrationpatterns.com/DataEnricher.html] from the [EIP patterns|Enterprise Integration Patterns] using a [Message Translator], an artibrary arbitrary [Processor] in the routing logic or using the [enrich|#enrich-dsl] DSL element to enrich the message. !http://www.enterpriseintegrationpatterns.com/img/DataEnricher.gif! ... to(activemq:Another.Queue); {code} If you want to use InOut (request-reply) semantics to process requests on the *My.Queue* queue on [ActiveMQ] with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this.: {code} from(activemq:My.Queue). ... {div:class=confluenceTableSmall} || Name || Default Value || Description || | {{uri}} | | The endpoint uri for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{ref}} | | Refers to the endpoint for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. | {div} ... {code} The content enricher ({{enrich}}) retrieves additional data from a _resource endpoint_ in order to enrich an incoming message (contained in the _original exchange_). An aggregation strategy is used to combine the original exchange and the _resource exchange_. The first parameter of the {{AggregationStrategy.aggregate(Exchange, Exchange)}} method corresponds to the the original exchange, the second parameter the resource exchange. The results from the resource endpoint are stored in the resource exchanges out-message. Heres an example template for implementing an aggregation strategy.: {code:java} ... .to(direct:result); {code} In the route above the message sendt to the {{direct:result}} endpoint will contain the output from the {{direct:resource}} as we do not use any custom aggregation. And in for Spring DSL you just omit the {{strategyRef}} attribute: {code:xml} route ... {code} h3. Content enrichment using {{pollEnrich}} The {{pollEnrich}} works just as the {{enrich}} however as it uses a [Polling Consumer] we have 3 methods when polling - receive ... {div:class=confluenceTableSmall} || Name || Default Value || Description || | {{uri}} | | The endpoint uri for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{ref}} | | Refers to the endpoint for the external service to enrich from. You must use either {{uri}} or {{ref}}. | | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. | | {{timeout}} | {{0}} | Timeout in millis to use when polling from the external service. See below for important details about the timeout. | {div} ... You can pass in a timeout value that determines which method to use - if timeout is -1 or other negative number then {{receive}} is selected - if timeout is 0 then {{receiveNoWait}} is selected - otherwise {{receive(timeout)}} is selected ... {code} If there is no file then the message is empty. We can use a timeout to either wait (potentially forever) until a file exists, or use a timeout to wait a certain period. For example to wait up til to 5 seconds you can do: {code:xml} route ... Full Content Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an arbitrary Processor in the routing logic or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use
[CONF] Apache Camel Content Enricher
Content Enricher Page edited by Claus Ibsen Changes (5) ... {anchor:enrich-dsl} h43. Content enrichment using the {{enrich}} DSL element Camel comes with two flavors of content enricher in the DSL ... This feature is available since Camel 2.0 h3. Enrich Options {div:class=confluenceTableSmall} || Name || Default Value || Description || | {{uri}} | | The endpoint uri for the external servie to enrich from. You must use either {{uri}} or {{ref}}. | | {{ref}} | | Refers to the endpoint for the external servie to enrich from. You must use either {{uri}} or {{ref}}. | | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. | {div} *Using the* *[Fluent Builders]* ... {code} h43. Content enrich using {{pollEnrich}} The {{pollEnrich}} works just as the {{enrich}} however as it uses a [Polling Consumer] we have 3 methods when polling - receive ... - receive(timeout) h3. PollEnrich Options {div:class=confluenceTableSmall} || Name || Default Value || Description || | {{uri}} | | The endpoint uri for the external servie to enrich from. You must use either {{uri}} or {{ref}}. | | {{ref}} | | Refers to the endpoint for the external servie to enrich from. You must use either {{uri}} or {{ref}}. | | {{strategyRef}} | | Refers to an [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] to be used to merge the reply from the external service, into a single outgoing message. By default Camel will use the reply from the external service as outgoing message. | | {{timeout}} | {{0}} | Timeout in millis to use when polling from the external service. See below for important details about the timeout. | {div} By default Camel will use the {{receiveNoWait}}. If there is no data then the {{newExchange}} in the aggregation strategy is {{null}}. ... {warning} h4. Example In this example we enrich the message by loading the content from the file named inbox/data.txt. {code} from(direct:start) .pollEnrich(file:inbox?fileName=data.txt) .to(direct:result); {code} And in XML DSL you do: {code:xml} route from uri=direct:start/ pollEnrich uri=file:inbox?fileName=data.txt/ to uri=direct:result/ /route {code} If there is no file then the message is empty. We can use a timeout to either wait (potential forever) until a file exists, or use a timeout to wait a period. For example to wait up til 5 seconds you can do: {code:xml} route from uri=direct:start/ pollEnrich uri=file:inbox?fileName=data.txt timeout=5000/ to uri=direct:result/ /route {code} {include:Using This Pattern} Full Content Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an artibrary Processor in the routing logic or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery and then send it on to another destination. For example using InOnly (one way messaging) from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this. from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); Here is a simple example using the DSL directly to transform the message body from("direct:start").setBody(body().append(" World!")).to("mock:result"); In this example we add our own Processor using explicit Java code from("direct:start").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + " World!"); } }).to("mock:result"); Finally we can use Bean Integration to use any Java method on any bean to act as the transformer from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); For further examples of this pattern in use you could look at
[CONF] Apache Camel Content Enricher
Content Enricher Page edited by Richard Kettelerij Comment: typo Changes (1) ... {{enrich}} is using a {{Producer}} to obtain the additional data. It is usually used for [Request Reply] messaging, for instance to invoke an external web service. {{poolEnrich}} {{pollEnrich}} on the other hand is using a [Polling Consumer] to obtain the additional data. It is usually used for [Event Message] messaging, for instance to read a file or download a [FTP|FTP2] file. This feature is available since Camel 2.0 ... Full Content Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an artibrary Processor in the routing logic or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery and then send it on to another destination. For example using InOnly (one way messaging) from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this. from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); Here is a simple example using the DSL directly to transform the message body from("direct:start").setBody(body().append(" World!")).to("mock:result"); In this example we add our own Processor using explicit Java code from("direct:start").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + " World!"); } }).to("mock:result"); Finally we can use Bean Integration to use any Java method on any bean to act as the transformer from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); For further examples of this pattern in use you could look at one of the JUnit tests TransformTest TransformViaDSLTest Using Spring XML route from uri="activemq:Input"/ bean ref="myBeanName" method="doTransform"/ to uri="activemq:Output"/ /route Content enrichment using the enrich DSL element Camel comes with two flavors of content enricher in the DSL enrich pollEnrich enrich is using a Producer to obtain the additional data. It is usually used for Request Reply messaging, for instance to invoke an external web service. pollEnrich on the other hand is using a Polling Consumer to obtain the additional data. It is usually used for Event Message messaging, for instance to read a file or download a FTP file. This feature is available since Camel 2.0 Using the Fluent Builders AggregationStrategy aggregationStrategy = ... from("direct:start") .enrich("direct:resource", aggregationStrategy) .to("direct:result"); from("direct:resource") ... The content enricher (enrich) retrieves additional data from a resource endpoint in order to enrich an incoming message (contained in the orginal exchange). An aggregation strategy is used to combine the original exchange and the resource exchange. The first parameter of the AggregationStrategy.aggregate(Exchange, Exchange) method corresponds to the the original exchange, the second parameter the resource exchange. The results from the resource endpoint are stored in the resource exchange's out-message. Here's an example template for implementing an aggregation strategy. public class ExampleAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange original, Exchange resource) { Object originalBody = original.getIn().getBody(); Object resourceResponse = resource.getOut().getBody(); Object mergeResult = ... // combine original body and resource response if (original.getPattern().isOutCapable()) { original.getOut().setBody(mergeResult); } else { original.getIn().setBody(mergeResult); } return original; } } Using this template the original exchange can be of any pattern. The resource exchange created by the enricher is always an in-out exchange. Using Spring XML The same example in the Spring DSL camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" route from uri="direct:start"/ enrich uri="direct:resource" strategyRef="aggregationStrategy"/ to uri="direct:result"/ /route route from uri="direct:resource"/ ... /route /camelContext bean
[CONF] Apache Camel Content Enricher
Content Enricher Page edited by Claus Ibsen Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an artibrary Processor in the routing logic or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery and then send it on to another destination. For example using InOnly (one way messaging) from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this. from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); Here is a simple example using the DSL directly to transform the message body from("direct:start").setBody(body().append(" World!")).to("mock:result"); In this example we add our own Processor using explicit Java code from("direct:start").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + " World!"); } }).to("mock:result"); Finally we can use Bean Integration to use any Java method on any bean to act as the transformer from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); For further examples of this pattern in use you could look at one of the JUnit tests TransformTest TransformViaDSLTest Using Spring XML route from uri="activemq:Input"/ bean ref="myBeanName" method="doTransform"/ to uri="activemq:Output"/ /route Content enrichment using the enrich DSL element Camel comes with two flavors of content enricher in the DSL enrich pollEnrich enrich is using a Producer to obtain the additional data. It is usually used for Request Reply messaging, for instance to invoke an external web service. poolEnrich on the other hand is using a Polling Consumer to obtain the additional data. It is usually used for Event Message messaging, for instance to read a file or download a FTP file. This feature is available since Camel 2.0 Using the Fluent Builders AggregationStrategy aggregationStrategy = ... from("direct:start") .enrich("direct:resource", aggregationStrategy) .to("direct:result"); from("direct:resource") ... The content enricher (enrich) retrieves additional data from a resource endpoint in order to enrich an incoming message (contained in the orginal exchange). An aggregation strategy is used to combine the original exchange and the resource exchange. The first parameter of the AggregationStrategy.aggregate(Exchange, Exchange) method corresponds to the the original exchange, the second parameter the resource exchange. The results from the resource endpoint are stored in the resource exchange's out-message. Here's an example template for implementing an aggregation strategy. public class ExampleAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange original, Exchange resource) { Object originalBody = original.getIn().getBody(); Object resourceResponse = resource.getOut().getBody(); Object mergeResult = ... // combine original body and resource response if (original.getPattern().isOutCapable()) { original.getOut().setBody(mergeResult); } else { original.getIn().setBody(mergeResult); } return original; } } Using this template the original exchange can be of any pattern. The resource exchange created by the enricher is always an in-out exchange. Using Spring XML The same example in the Spring DSL camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" route from uri="direct:start"/ enrich uri="direct:resource" strategyRef="aggregationStrategy"/ to uri="direct:result"/ /route route from uri="direct:resource"/ ... /route /camelContext bean id="aggregationStrategy" class="..." / Aggregation strategy is optional The aggregation strategy is optional. If you do not provide it Camel will by default just use the body obtained from the resource. from("direct:start") .enrich("direct:resource") .to("direct:result"); In the route above the message send to the direct:result endpoint will contain the output from the direct:resource as we do not use any custom aggregation. And in Spring DSL you just omit the strategyRef attribute: route from uri="direct:start"/ enrich uri="direct:resource"/ to uri="direct:result"/ /route Content enrich using pollEnrich The pollEnrich works just as the enrich however as it uses a Polling Consumer we have
[CONF] Apache Camel: Content Enricher (page edited)
Page Edited : CAMEL : Content Enricher Content Enricher has been edited by Claus Ibsen (Jun 09, 2009). (View changes) Content: Content Enricher Camel supports the Content Enricher from the EIP patterns using a Message Translator, an artibrary Processor in the routing logic or using the enrich DSL element to enrich the message. Content enrichment using a Message Translator or a Processor Using the Fluent Builders You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery and then send it on to another destination. For example using InOnly (one way messaging) from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); If you want to use InOut (request-reply) semantics to process requests on the My.Queue queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this. from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); Here is a simple example using the DSL directly to transform the message body from("direct:start").setBody(body().append(" World!")).to("mock:result"); In this example we add our own Processor using explicit Java code from("direct:start").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + " World!"); } }).to("mock:result"); Finally we can use Bean Integration to use any Java method on any bean to act as the transformer from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); For further examples of this pattern in use you could look at one of the JUnit tests TransformTest TransformViaDSLTest Using Spring XML route from uri="activemq:Input"/ bean ref="myBeanName" method="doTransform"/ to uri="activemq:Output"/ /route Content enrichment using the enrich DSL element This feature is available since Camel 2.0 Using the Fluent Builders AggregationStrategy aggregationStrategy = ... from("direct:start") .enrich("direct:resource", aggregationStrategy) .to("direct:result"); from("direct:resource") ... The content enricher (enrich) retrieves additional data from a resource endpoint in order to enrich an incoming message (contained in the orginal exchange). An aggregation strategy is used to combine the original exchange and the resource exchange. The first parameter of the AggregationStrategy.aggregate(Exchange, Exchange) method corresponds to the the original exchange, the second parameter the resource exchange. The results from the resource endpoint are stored in the resource exchange's out-message. Here's an example template for implementing an aggregation strategy. public class ExampleAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange original, Exchange resource) { Object originalBody = original.getIn().getBody(); Object resourceResponse = resource.getOut().getBody(); Object mergeResult = ... // combine original body and resource response if (original.getPattern().isOutCapable()) { original.getOut().setBody(mergeResult); } else { original.getIn().setBody(mergeResult); } return original; } } Using this template the original exchange can be of any pattern. The resource exchange created by the enricher is always an in-out exchange. Using Spring XML The same example in the Spring DSL camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" route from uri="direct:start"/ enrich uri="direct:resource" strategyRef="aggregationStrategy"/ to uri="direct:result"/ /route route from uri="direct:resource"/ ... /route /camelContext bean id="aggregationStrategy" class="..." / Aggregation strategy is optional The aggregation strategy is optional. If you do not provide it Camel will by default just use the body obtained from the resource. from("direct:start") .enrich("direct:resource") .to("direct:result"); In the route above the message send to the direct:result endpoint will contain the output from the direct:resource as we do not use any custom aggregation. And in Spring DSL you just omit the strategyRef attribute: route from uri="direct:start"/ enrich uri="direct:resource"/ to uri="direct:result"/ /route Using This Pattern If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07,