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. If different message types have distinct selection values, each consumer that is specialized for a particular type will only receive messages of that type. This approach facilitates sending many message types using a small number of channels, which can be beneficial in an enterprise that requires more channels than their 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 de-facto language for designing asynchronous, distributed systems. Over 100,000 copies sold.

Software Architect Elevator book cover

The Software Architect Elevator
Rethink the role of architects as a connecting element across organizational layers. Acquire the technical, communication, and organizational skills to succeed in this new role.

Cloud Strategy book cover

Cloud Strategy
Make your cloud migration a success by translating high-level goals into conscious decisions with well-understood trade-offs.

Platform Strategy book cover

Platform Strategy
Platforms can boost innovation through harmonization, but they aren't easy to build. Learn from over a decade of designing and rolling out IT platforms.