[ Team LiB ] |
C.2 Message Client Patterns
GoalTo distribute message processing across multiple consumers, allowing multiple messages to be processed in parallel (Figure C-1). Figure C-1. Competing consumersParticipants
InteractionsOne or more applications send messages to a queue. Multiple consumers access the queue, each reading different messages and processing them. Each message is read from the queue by one and only one consumer. NotesThe Competing Consumers pattern is best implemented using JMS, as Internet mail providers generally do not support multiple readers on a single mailbox terribly well.
GoalTo deliver messages to a client as quickly as possible, while minimizing the complexity of the code, the developer must assemble to handle messages. Participants
InteractionsIncoming messages are delivered to the message server. The application server communicates with the message server and retrieves new messages destined for a particular client. When new messages arrive, the application server calls appropriate client code to process them. NotesMessage-driven EJBs implement the Event-Driven Consumer pattern. JMS also supports implementing event-driven consumers directly. JavaMail supports event-driven consumers via the FolderListener interface, although we do not recommend it. Most event-driven consumer implementations simply push implementation to the application server/application framework level, while still implementing a polling consumer behind the scenes.
GoalTo hide business logic behind a standard façade that can be accessed asynchronously and maintained independently (Figure C-2). Figure C-2. Message façadeParticipants
InteractionsThe client creates a command message and sends it to the message façade using any sort of message transport. The façade receives the message (using a polling consumer or an event-driven consumer) and uses the information it contains to access business tier code to fulfill a use case. Optionally, a return message is sent to the client confirming successful completion of the use case and returning data. NotesAlso see the Business Delegate and Session Façade patterns.
GoalDecouple the code responsible for the processing of messages from the code responsible for receiving messages. Provide a simpler framework for testing message-handling code. Participants
InteractionsThe message client is responsible for retrieving messages from a transport mechanism, via JavaMail, JMS, or other technologies. Once a message is received, it is handed off to a separate message handler object, which is responsible for processing the message content. NotesThe message handler design is a building block for more complex client designs.
GoalTo manage multiple types of messages on a single message channel. Participants
InteractionsSenders transmit messages to a single message channel. Each message includes identifying information, such as headers, that can be used to determine the purpose of the message. The client reads the channel and selects the messages it is capable of handling. NotesMessage selectors can be implemented in JMS using the built-in selection criteria API, which allow you to add SQL-like selection criteria to a Queue or a Topic.
GoalAllow an application to participate in a messaging exchange without requiring that the application be running 100% of the time and without requiring a continuous two-way connection with the messaging server. Participants
InteractionsAs messages for a particular client arrive at the message server, the server stores each incoming message in a holding area. The client periodically contacts the message server and issues a request for all new messages intended for it. The message server transmits all of the held messages to the client, which processes them. NotesAll consumers working with POP3 implement the Polling Consumer pattern. JMS consumers have a wider variety of options, including the Event-Driven Consumer pattern. |
[ Team LiB ] |