Name

Publish-Subscribe Pattern

Goal

Send a single copy of a message for delivery to multiple recipients who may or may not be individually known to the sender.

Participants

Sender

Originates a message of a particular type.

Messaging server

Accepts a message from a sender and delivers it to zero or more recipients.

Recipients

Register to receive (subscribe to) a particular type of message.

Interactions

Rather than identify a particular recipient, the sender identifies a message as being of a certain type. Recipients may then register with the messaging server as being interested in receiving all messages of a particular type. When a sender creates a new message, all recipients who have expressed interest in receiving messages of that type will receive a copy.

Notes

In a JMS environment, publish-subscribe is implemented via the Topic interface. In an SMTP/JavaMail environment, implementing publish-subscribe requires additional infrastructure, either within your application or within your mail server.

Get J2EE Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.