Home > Articles > Programming > Java

This chapter is from the book

This chapter is from the book

Messaging Domain Models

JMS supports two types of messaging models (also referred to as domain models) that are common in the messaging world: Point-to-Point (P2P) and Publish/Subscribe (pub/sub). Not all messaging middleware supports both models, and the JMS 1.02 specification doesn't require the JMS provider to support both models. Regardless of the messaging model, JMS clients exchange messages by sending or retrieving messages to and from a virtual address termed the "destination." JMS providers are responsible for destination services.

Point-to-Point Model

The P2P messaging model consists of message senders, receivers, queues, and the messages. A JMS client that generates messages is called the sender; a JMS client that consumes messages is called the receiver. In the P2P model, a sender sends a message to a destination called the queue; a receiver retrieves the message from the same queue, as shown in Figure 12-4.

Figure 12-4 A message sent to a queue being consumed by only one receiver

Figure 12-4 illustrates the P2P messaging model with three senders sending messages to a destination queue called OrderQueue and the two receivers each retrieving their own message. The P2P messaging model is applicable in cases where messages should be acted upon only once. For example, a company may have its distribution warehouse in a state different from its headquarters. When customers order products, the application sends the order messages to a JMS client at the remote warehouse where the order is processed and shipped.

The P2P domain model has several significant characteristics:

  • The P2P model is referred to as supporting either one-to-one or many-toone relationships. If you look at the sender-receiver relationship where many JMS senders can send messages to a particular JMSQueue destination, the message can only be consumed by a single receiver. On the other hand, if you look at the message-receiver relationship, there can only be one receiver per message, resulting in a one-to-one relationship. The P2P model can be characterized as supporting a many-to-one relationship between senders and a single receiver.

  • Each message can have only one receiver. Therefore, multiple senders can send messages to a queue and multiple receivers can access the queue, but only one receiver can consume a message from that queue.

  • Once a message is consumed by a receiver, it's removed from the queue. Thus, in the P2P model, messages are guaranteed to be delivered to a receiver once and only once.

  • Messages are ordered. For example, a queue delivers messages to consumers in the order in which they were placed by the provider.

  • Senders and receivers can be added dynamically at runtime, thus allowing the system to grow or shrink with the demand.

Publish and Subscribe Model

The pub/sub model consists of message publishers, subscribers, and topics. A message producer is called a publisher; a message consumer is called a subscriber. The destination where a publisher sends messages and the subscribers retrieve the messages is called the topic. The pub/sub model is based on the concept of nodes in a content hierarchy, where a publisher publishes messages to a destination and the messages are broadcast to all registered subscribers. The pub/sub model supports many-to-many or one-to-many relationships. When considering a publisher-subscriber relationship, there can be many publishers sending messages to many subscribers, resulting in a many-to-many relationship. On the other hand, when considering a message-subscriber relationship, a message sent by a publisher is distributed to all registered subscribers resulting in a one-to-many relationship. The pub/sub model can be characterized as supporting a many-to-many relationship between senders and receivers. Note that every client that subscribes to a topic receives its own copy of the messages published to that topic. Messages are pushed to the registered subscribers without having to request them. Also, publisher and subscribers can be dynamically added at runtime, and a message delivery in pub/sub is once or not at all. Figure 12-5 is an illustration of the pub/sub messaging model in which many publishers are publishing messages to a destination topic, StockQuoteTopic. Each of these messages is distributed to many subscribers. The pub/sub model is applicable when one wants to broadcast a message to many clients simultaneously. For example, a financial website can publish the latest stock quotes to a topic; clients that have subscribed to a specific topic can automatically receive the latest stock price information.

Figure 12-5 A message sent to a topic being broadcast to one or more registered subscribers

Message Delivery

JMS message consumers, whether P2P or pub/sub, can choose to have messages delivered to them asynchronously by having the JMS provider push messages, or they may receive the messages synchronously by connecting to the JMS provider and receiving, or pulling, the messages from the destination. Pull delivery requires the JMS consumer to either stay connected to the JMS provider and poll the destination for messages or connect to the JMS provider and retrieve messages from the destination per regularly scheduled intervals. Note that polling the destination for messages adds extra overhead to the system. Push delivery is simpler as the JMS provider automatically delivers messages to registered JMS consumers. Developers incorporate the pull or the push delivery mechanism based on the business logic requirements. Note that the communication between the producer client and the JMS provider is synchronous—a message producer (JMS client producer) connects to the JMS provider, sends messages, and receives acknowledgment from the provider to complete message delivery. In contrast, message consumers can either receive messages synchronously as they arrive at the destination (if the pull option is used) or asynchronously if the push option is used in the client code. Regardless of the options used, message delivery from producer to consumer can only be asynchronous. Figure 12-6 illustrates the push/pull model where a message producer client sends messages to a destination.

Figure 12-6 JMS architecture with interaction among clients, provider, and messages

Guaranteed Message Delivery

JMS messages can be marked as either persistent or nonpersistent. In both cases, a JMS provider will attempt to deliver the message to the consumer until the JMS consumer either receives the message and acknowledges it, or until the message expires. The difference between a persistent and a nonpersistent message is significant, yet subtle. If a message is marked as persistent, the JMS provider saves the message on the disk before acknowledging to the message producer and uses a store-and-forward mechanism. Delivery is attempted until the JMS message consumer receives the message and acknowledges it, or until the message expires. Even if the provider crashes before the message is delivered to the consumer, the provider will attempt to resend the message after the provider is rebooted. With nonpersistent messaging, the JMS provider doesn't save the message to disk before sending an acknowledgment to the message producer. For this reason, if the JMS provider were to experience a system crash before delivery of the message, the nonpersistent message would be lost.

In a pub/sub model, a subscriber can either be durable or nondurable. Messages are delivered to nondurable subscribers only if they're connected to the provider. With durable subscribers, the provider is responsible for storing the messages and will deliver unexpired messages when durable subscribers connect later. A message can be marked persistent and durable or nonpersistent and durable—there's a subtle but important difference. In the case of a nonpersistent and durable message, the provider attempts to deliver the message, and if the subscriber isn't active, then the provider will store the message for future delivery attempts. If the provider crashes before it's able to store the message, then the message is lost and will never be delivered. This won't happen with the persistent and durable message because when the message is received from the publisher it's already saved on disk and will attempt to deliver the durable message on reboot. Making a message durable and/or persistent has consequences for processing and system resources. For example, confirmation of purchased messages could be marked persistent and durable because that message cannot afford to be lost. However, stock price update broadcast messages every few minutes could be nonpersistent and nondurable, because most people (except for day traders) can afford to lose a message or two without adversely affecting their net worth.

Loose Coupling and Asynchronous Communication

In the JMS messaging architecture, the JMS clients can produce or consume messages or do both. The JMS provider is responsible for routing and delivery of messages. The JMS clients are loosely coupled and asynchronous; neither JMS client needs to be aware of the other, nor must they be running simultaneously for messages to be exchanged. JMS clients don't communicate directly but via the destination service provided by the JMS provider. Producers send messages to a destination, where they are held until consumers retrieve messages or the messages expire.

Even though the communications between JMS clients are asynchronous, the communication between producers and a JMS provider are synchronous, and the communication between consumers and a JMS provider are synchronous or asynchronous. When JMS clients send or receive messages from JMS provider destinations, they go through a receive-acknowledge handshake. Refer back to Figure 12-6 for an illustration.

Loose coupling and asynchronous communication in a JMS application give enterprise applications flexibility when implementing business workflow processes. Let's look at an e-commerce application example. During checkout, after the shopping cart component sends a persistent and durable message to a JMS provider OrderQueue destination, the component can continue servicing other customers and not worry about what happens next. An optimized order processing application retrieves the message from the OrderQueue destination and processes it. Per the application business logic that requires minimizing shipping costs, reduced delivery time, and maximum profit, the application forwards this durable message to the NYWarehouseQueue destination nearest the customer's shipping address. The shipping application then retrieves the message from the NYWareHouseQueue, extracts the necessary information, and mails the product, as well as automatically sending an e-mail with a tracking order number to the customer. As the JMS application is loosely coupled and relies on asynchronous communication, the shopping cart application is unaware of the optimized order processing application. As a result, if the shipping application and order processing go down for a while, the persistent and durable message is still delivered. When the two failed applications resume operating, the order can be completed and the products shipped.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020