Selective Consumer

Camel supports the Selective Consumer from the EIP patterns book.

How can a message consumer select which messages it wishes to receive?


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 Components which supports message selecting.

  • Using the 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 JMS selector parameter so that the message broker will only deliver messages matching your criteria.


And in XML:

  <from uri="jms:queue:hello?selector=color='red'"/>
  <to uri="bean:red"/>

Selective Consumer using Filter EIP

The other approach is to use a Message Filter which is applied; if the filter matches the message your "consumer" is invoked as shown in the following example:


And in XML

    <from uri="seda:colors"/>
        <simple>${header.color} == 'red'</xpath>
        <to uri="bean:red"/>