Chapter 5. Publish-and-Subscribe Messaging
This chapter focuses on the publish-and-subscribe (pub/sub) messaging model. This messaging model is used when you need to broadcast an event or message to many message consumers. Unlike the point-to-point messaging model discussed in Chapter 4, all message consumers (called subscribers) listening on the topic will receive the message.
In this chapter, we will describe the publish-and-subscribe model
through the use of a typical broadcast messaging scenario where a mortgage
lender publishes its latest mortgage rates for a 30-year fixed mortgage to
various borrowers in the hope of attracting one of the borrowers to apply for
a mortgage loan. The TLender
class will
publish a new mortgage rate through a topic, and the TBorrower
class will subscribe to the topic and
make a decision on whether or not it is a good rate.
We have mentioned several new terms already in this chapter: topic, subscriber, and publish. Before moving on to the code example, we will first describe the main characteristics and nomenclature of the publish-and-subscribe model and discuss some of the typical use cases for this model.
Publish-and-Subscribe Overview
The publish-and-subscribe model is more commonly referred to as the pub/sub model. In this model, the message producer is called a publisher and the message consumer a subscriber. Messages are published to a topic as opposed to being sent to a queue, as in the point-to-point model. The most important characteristics ...
Get Java Message Service, 2nd Edition 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.