This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 8fdb9e3 CAMEL-16861: Cleanup and update EIP docs 8fdb9e3 is described below commit 8fdb9e359b11b0d4dda07440f2bad65cf337cef2 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Oct 18 11:10:23 2021 +0200 CAMEL-16861: Cleanup and update EIP docs --- .../modules/eips/pages/selective-consumer.adoc | 47 ++++++++++++++++------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/selective-consumer.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/selective-consumer.adoc index 81c923d..d3f017d 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/selective-consumer.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/selective-consumer.adoc @@ -4,31 +4,51 @@ Camel supports the https://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageSelector.html[Selective Consumer] from the xref:enterprise-integration-patterns.adoc[EIP patterns] book. -The Selective Consumer from the EIP patterns can be implemented in two ways +How can a message consumer select which messages it wishes to receive? image::eip/MessageSelectorSolution.gif[image] -== Selective Consumer using Components +Make the consumer a Selective Consumer, one that filteres the messages delivered by its channel so that it only receives the ones that match its criteria. + +== Using Selecting Consumer + +In Camel the Selective Consumer EIP is implemented in two ways: + +- Using xref:components::index.adoc[Components] which supports message selecting. +- Using the xref:filter-eip.adoc[Filter] EIP as message selecting. + +=== Selective Consumer using Components The first solution is to provide a Message Selector to the underlying URIs when creating your consumer. -For example when using JMS you can specify a selector parameter so that the message broker will only deliver messages matching your criteria. +For example when using xref:components::jms-component.adoc[JMS] you can specify a +JMS selector parameter so that the message broker will only deliver messages matching your criteria. [source,java] ---- -from("activemq:queue:hello?selector=color='red'") +from("jms:queue:hello?selector=color='red'") .to("bean:red"); ---- -== Selective Consumer using Filter pattern +And in XML: + +[source,xml] +---- +<route> + <from uri="jms:queue:hello?selector=color='red'"/> + <to uri="bean:red"/> +</route> +---- + +=== Selective Consumer using Filter EIP The other approach is to use a xref:filter-eip.adoc[Message Filter] which is applied; -then if the filter matches the message your consumer is invoked as shown in the following example. +if the filter matches the message your "consumer" is invoked as shown in the following example: [source,java] ---- -from("seda:a") - .filter(header("foo").isEqualTo("bar")) - .process(myProcessor); +from("seda:colors") + .filter(header("color").isEqualTo("red")) + .to("bean:red") ---- And in XML @@ -36,10 +56,11 @@ And in XML [source,xml] ---- <route> - <from uri="seda:a"/> + <from uri="seda:colors"/> <filter> - <simple>${header.foo} == 'bar'</xpath> - <process ref="myProcessor"/> + <simple>${header.color} == 'red'</xpath> + <to uri="bean:red"/> </filter> </route> ----- \ No newline at end of file +---- +