Suppose the phone only calls in real time. No e-mail and SMS feature occurred? A phone call back. Just not enough time to connect, and then pass on this phone message is definitely not acceptable. Save them. When the user needs to see the information to get information? Along with this doubt. Short interest and message came into being, whether the phone is turned on or not, we can get the information. JMS provides similar functionality. In this chapter we will systematically learn about the important content in JMS.
Ø Mastering the basic concept of JMS and its scope of application
Ø difference between point-to-point model and advertisement/subscription model and use occasions
Ø familiarity with the core and common JMS APIs
Ø familiar with and understand the steps of jmsclient development
Ø the implementation of message synchronization and asynchronous reception
Ø the method of solving the problem of string package
Enterprise Messaging System
The Java Message Service, developed by Sun, provides a way for Java programs to access enterprise messaging systems. Before we discuss JMS, let's break down the enterprise messaging system.
Enterprise messaging systems, which are message-oriented middleware (MOM). Provides a mechanism for integrating applications in a loosely coupled, flexible way. They provide asynchronous data transmission between storage-and-forwarding-based applications, where applications do not communicate directly with each other, but rather communicate with mom as a mediator. MOM provides a guaranteed message delivery. Application developers do not need to know the details of remote procedure calls (PRC) and network/communication protocols. ACTIVEMQ is a good member of MOM.
Benefits of the Enterprise messaging system
Let's take a look at this, application a sends a message to the server, and then application B receives a send from the server, and through this diagram we analyze the benefits of JMS
Figure 1 JMS Communication
Provides message flexibility
Application A communicates with application B by using the Application Programming Interface (API) of MOM to send messages. MOM routes the message to Application B so that the message can exist in MOM, and MOM handles network traffic. Assume that the network connection is not available. MOM stores the message until the connection becomes available, and then forwards the message to application B.
There is one aspect of flexibility that is now. When application a sends its message. Application B may not even be in a running state.
MOM will keep this message. Until application B starts running and tries to retrieve the message.
This also prevents application a from clogging up by waiting for application B to retrieve messages.
Such asynchronous communication requires that the design of the application is different from most applications today, but it may be a very de facto method for time-independent or parallel processing.
Loosely coupled
The real power of enterprise messaging systems is the loose coupling of applications.
In the diagram above, application A sends a message specifying a specific target. such as "Order Processing". Today, the order Processing feature is provided by Application B.
In the future, however, we can replace application B with different order handlers. Application A will no longer be a smart choice. The replacement application will continue to send the message complete "Order Processing". And the message will still be processed.
Same, we can also replace application A, just to replace the application to continue sending messages for "order Processing", the order handler does not need to know if there is a new application in the sending order.
What is JMS
JMS is a collection of interfaces and related semantics, through these interfaces and the methods therein. Jmsclient How to access the message system. Finished creating, sending, receiving, and reading messages in the Enterprise messaging system.
Prior to JMS, each MOM vendor used a proprietary API to provide applications with access to their products. It is commonly used in many languages, including the Java language. JMS provides a standard, convenient way for Java programs to send and receive messages through MOM. Programs written in JMS can be executed on any mom that implements the JMS standard.
The key to JMS portability is that the JMS API is provided by Sun as a set of interfaces. The product that provides the JMS functionality is done by providing a provider that implements these interfaces. Developers can define a set of messages and a set of applications that exchange these messages. Establish a JMS application for asynchronous communication.
The target of JMS
JMS since the proposed. Committed to completion such as the following goals:
Defines a set of message common concepts and useful tools.
All Java applications are able to use the APIs defined in JMS to complete the creation, reception, and delivery of messages, regardless of what mom, which implements the JMS standard, can be used as a mediator of the message and the storage and forwarding of the message is complete.
maximizes portability of messaging applications.
MOM provides guaranteed message delivery, and application developers do not need to know the details of remote procedure calls (PRC) and network/communication protocols to provide portability of the program.
Maximize the degree of coupling between your application and your application system.
because of the presence of MOM, each application only cares about how to receive and send messages to and from mom without having to focus on the other side of mom. How other programs are received and sent.
JMS Two message models
JMS provides two types of message communication models:
O-To-point (peer) model
Ø Announcement/Subscription (PUB/SUB) model
Figure 2 JMS Communication model
It can be seen that Clienta and CLIENTB are news producers. Messages are sent to Clientc, Clientd, Cliente, and clientf, respectively, through two different destinations.
The message between Clienta, C, and D is a point-to-point model. Using such a model, the client sends a message to the queue destination. Only one message receiver from this queue can receive the message. Other visitors to the same destination do not receive the message. such as CLIENTC receive MSG1 messages in the queue. CLIENTD receives the MSG2 message in the queue.
The message between CLIENTB, E, and F is the Publish/subscribe model. Use such a broadcast model. A client sends a message to the subject destination (Topic). No matter what number of consumer subscribers are able to receive them from this subject destination. such as: Cliente and clientf both receive this MSG3 message.
Dot-to-point model
Point-to-point delivery model: A producer sends a message to a particular queue, and the consumer gets a message from a message queue, for example, as seen:
Figure 3 Point-to-dot communication model
Features of the point-to-point model:
Ø each message has a consumer
There is only one consumer for each article, assuming that a message is received by the person receiving the message. Then other consumers will not be able to get the message.
Ø sending and receiving messages is not related to time
Other words. After the producer sends the message, the consumer can receive at random moment, but has two premise:
1. Message Not expired
2, the message is not received by other users
Consumers are also able to execute first. When a producer executes a message and sends it to a queue, the consumer can get a message from the queue, which is called "Waiting."
Ø the consumer must acknowledge receipt of the message
When a message is received, the consumer must confirm that the message has been received, or the JMS service provider will feel that the message has not been received, and the message can still be received by others. The program can proactively confirm. No manual intervention is required.
Ø non-persistent messages are sent at most only once
Non-persistent messages are sent at most once. Indicates that a message might not have been sent. Causes that are not sent may be:
1, the JMS service provider is down, etc., resulting in the loss of non-persistent information
2. Messages in the queue expire and are not received
Ø persistent messages are sent strictly once
We are able to set more important messages as persistent messages. Messages that persist are not lost because of a failure of the JMS service provider or for other reasons.
Publish/Subscribe Model
Announcement/subscription Model: The advertisement/subscription delivery message type is related to the subject (TOPIC). Producers publish messages, and consumers subscribe to messages of interest, and producers link messages to a specific subject (TOPIC), and the messaging System (MOM) is based on consumer interest. Deliver the message to the consumer.
Such types are similar in the form of published newspapers, magazines, for example with what is seen:
Figure 4 Announcement/subscription communication model
Announcement / features of the subscription model:
Ø each message can have more than one (0,1, ...). ) Subscribers
Each message can have more than one consumer, assuming that newspapers and magazines, who subscribe to who can be obtained.
Subscribers can only consume the information they have published after their subscription
This requires that you have to open the subscription first. The producer then releases. The user must first execute. The executive producer waits for this different type.
Ø Subscribers must maintain the active ability to use this information
The user must keep the activity waiting for the publisher to announce the message, assuming that the user only makes announcements after the announcement, you cannot let those previously published messages be published.
Brief introduction to JMS (i)--JMS