Enterprise Integration Patterns
Messaging Patterns
HOME PATTERNS RAMBLINGS ARTICLES TALKS DOWNLOAD BOOKS CONTACT
Messaging Patterns
Selective ConsumerSelective ConsumerMessaging Patterns » Messaging Endpoints

An application is using Messaging. It consumes Messages from a Message Channel, but it does not necessarily want to consume all of the messages on that channel, just some of them.

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.

There are three parts to this filtering process:

  1. Specifying Producer — Specifies the message’s selection value before sending it.
  2. Selection Value — One or more values specified in the message that allow a consumer to decide whether to select the message.
  3. Selective Consumer — Only receives messages that meet its selection criteria.

When multiple Selective Consumers are used with a Point-to-Point Channel, they effectively become Competing Consumers that are also selective. If two consumer’s criteria overlap, and a message’s selection value meets both of their criteria, either consumer can consume the message. Consumers should be designed to ensure that at least one of them is eligable to consume every valid selection value. Otherwise, a message with an unmatched selection value will never be consumed and will clutter the channel forever (or at least until Message Expiration occurrs).

When multiple Selective Consumers are used with a Publish-Subscribe Channel, each message will be delivered to each subscriber, but a subscriber will simply ignore its copy of a message that does not fit its criteria. Once a consumer decides to ignore a message, the messaging system can discard the message since it has been successfully delivered and will never be consumed. A messaging system can optimize this process by not even delivering a message it knows the consumer will ignore, thereby decreasing the number of copies of a message that must be produced and transmitted. This behavior of discarding ignored messages is independent of whatever Guaranteed Delivery, Durable Subscriber, and/or Message Expiration settings are used.

Selective Consumers make a single channel act like multiple Datatype Channels. Different types of messages can have different selection values, so that a consumer that is specialized for a particular type will only receive messages of that type. This can facilitate sending a large number of types using a small number of channels. This approach can also conserve channels in an enterprise which requires more channels than a messaging system can support.


Competing, Selective Consumers

... Read the entire pattern in the book Enterprise Integration Patterns

Related patterns:

Competing Consumers, Content-Based Router, Correlation Identifier, Datatype Channel, Durable Subscriber, Event-Driven Consumer, Message Filter, Guaranteed Delivery, Invalid Message Channel, Message, Message Channel, Message Dispatcher, Message Expiration, Messaging, Point-to-Point Channel, Polling Consumer, Publish-Subscribe Channel, Request-Reply, Transactional Client


Creative Commons Attribution License

You can reuse the following elements under the Creative Commons Attribution license: pattern icon, pattern name, problem and solution statements (in bold), and the sketch. Other portions are protected by copyright.

Enterprise Integration Patterns book cover

Enterprise Integration Patterns
The classic, as relevant as ever. Over 90,000 copies sold.

Software Architect Elevator book cover

The Software Architect Elevator
Learn how architects can play a critical role in IT transformation by applying their technical, communication, and organizational skills.

Cloud Strategy book cover

Cloud Strategy
Fill the large gap between high-level goals and product details by understanding decision trade-offs.