Message Queue Study -- reprinted

Source: Internet
Author: User

Improve applications by using Queue TechnologyProgram.

Shorten wait time

In general, the work that the application needs to process is divided into the work that must be completed immediately and that can be postponed to a later time. This method is meaningful.

Anything that does not affect the user's submission of the next page can be processed in the background. Batch update, summary calculation, and external processing are all suitable for the background.

Queue is a technology that effectively divides the processing of applications into foreground and background tasks. When the processing capacity permits, this technology plays a role by storing messages, determining the priority of message processing, and submitting messages to applications. It allows you to balance the load on your local computer or allocate tasks to a remote computer.

To reduce user waiting time, the application can queue messages that require background processing. Then the processing task can be removed from the page submission process. A background process reads and queues these messages, or even a separate system can process them.

Java Message Management System

Java Message Service (JMS) is actually an interface used to access the enterprise message management system, rather than a system. JMS extracts the differences between Message Implementation Solutions of various vendors. The idea is to enable applications compiled according to the jms api to be transplanted between different message products.

In fact, there is usually a trade-off between portability and functionality. Although JMS is applicable to applicationsCode(But not configured) portability provides some evaluation methods, but it rarely provides shared standards for access to messaging system features.

JMS provides two programming models: point-to-point (P2P) model and publish-and-subscribe, pub/Sub Model. The JMS specification calls them the message transmission field.

In the P2P message transmission model, each message is sent to a receiver through a queue. The P2P model ensures that only one receiver can read each message. If multiple receivers in the queue are listening (for example, when a queue has a message-driven bean pool), the JMS provider will publish each message to one of the recipients. The P2P message model is most suitable for transaction messages.

In the pub/sub message transmission model, a message producer can send a message to one or more registered consumers based on the topic. A consumer can subscribe to a topic. Subscription can be continuous, which allows consumers to disconnect from messages and re-connect and retrieve missed messages. You can regard the pub/sub message model as a broadcast service-it is most suitable for publishers who are not very interested in missed messages.

As JMS is only an interface, it needs to be implemented to complete the actual work. Oracle JMS (ojms) is a high-quality JMS provider. It is based on Oracle Advanced Queue Management (Advanced Queuing ).

Oracle Advanced Queue Management

Advanced queue management is a feature of Oracle databases. It provides message queue management functions. This is a very reliable, secure, and scalable message management system, because it uses the same database features as other Oracle-based applications.

A major advantage of advanced queue management is that it can be accessed through PL/SQL, Java, or C, in this way, you can import messages from a Java Servlet into the queue and make the same messages in the PL/SQL stored procedure out of the queue.

Another advantage of advanced queue management is that you can use this software to spread messages between remote nodes through Oracle Net Services (SQL * Net), HTTP (s), and SMTP. Advanced queues can even be integrated with non-Oracle message management systems (such as IBM MQSeries) through message gateway.

Oracle Advanced Queue Management provides single-consumer and multi-consumer queues. A single consumer queue only targets a single receiver. A multi-consumer queue can be used by multiple recipients. When a message is put into a multi-consumer queue, the application programmer must explicitly specify these receivers in the message attributes, or establish a rule-based subscription process that determines the recipients of each message.

The two types of queues provided by advanced queue management correspond to the two message transmission fields presented by JMS.Table 1Summarizes the relationship between two types of message transmission styles.

Message Type General application scenarios Base JMS domain Oracle Advanced queue management type
Point-to-Point Transactions 1-to-1 Queue Single consumer
Publish/Subscribe Broadcast 1-to-many Topic Multiple consumers

Table 1: Comparison of message transmission styles


Remember that the features and concepts provided by advanced queue management are not available in JMS. For example, Oracle Advanced queue allows messages to have multiple named recipients, but JMS does not. Although writing code according to the jms api is generally enough, remember that you may also need to write your own Java advanced queue API to access all the messaging functions of Oracle.

Message-driven beans

Message-driven beans (mdb, message-driven beans) is an Enterprise JavaBean (EJB) that uses JMS messages. MDB is managed by the J2EE application server. It listens to messages and maintains MDB instance pools, and automatically calls these instances to receive and process messages.

MDB is easier to write than JMS applications because the application server processes the runtime environment of MDB, including transactions, security, and consistency. This provides developers with a great advantage, from which developers can free up and focus on the business logic of message processing. When a message arrives in a queue, an MDB instance is automatically created to process the message and then the instances are cleared.

Note that MDB is based on JMS, so they inherit the limitations of the jms api; that is, you cannot access all functions of the underlying message management system.

However, you should generally use MDB when you can use it, because the complexity inherent in the application server's management of multi-thread asynchronous message listeners. For code that cannot be run on the application server, such as a separate client application, it has been proved that JMS is also useful (although more complex ).


I have previously pointed out that anything that does not affect the user's submission of the next page applies to queue processing. However, it may not always be obvious how to further improve the response speed that users can perceive.

For this improvement, you can raise such a question to change the way you consider the workflow: "What is the minimum work that must be done to enable the user to work continuously? "Maybe you need to question the assumptions of the task itself.

I completed a web application for an insurance company, which was used by the company's telephone service staff to handle member status changes by phone. The application must be connected to two different original systems to update and verify data.

Assume that the customer wants to change her address to another address in another State. The telephone service personnel enter the information in the web form and click the submit button. The Web application forwards the transaction to two different host applications: one is the health plan management application and the other is the retirement benefit management application. When the health plan management application verifies the address change, the verification result indicates that the current health plan of the customer is invalid in the new State.

Is there any problem? It takes too long to interact with the original system. There is also a reliability problem: If a host is offline or any part of the connected infrastructure goes down, all telephone service personnel cannot answer the call.

In addition, managers insist that all processing should be completed before the next page of the Web application is displayed. They believe that Web applications must solve all the issues of transaction processing before the user hangs up.


This solution challenges the assumption that all data must be verified before the user can proceed to the next task. In this case, we find that there are very few problems that require extra input from customers. The company made a design decision: If everything runs well, let the customer first stop the call and then call the customer back when there is a problem. This case is less than 1%.

Web applications are re-designed using the HTML framework and a small amount of JavaScript. javascript can regularly check the server to discover issues that need attention.

By rethinking workflow and application queue technology, the company has been able to improve system reliability and respond to user and customer requests quickly.

Further steps

For advanced queue management, ojms, and JMS, remember the following points:

    • when creating a queue for advanced queue management, you must use the ojms type (such as sys. AQ $ _ JMS _ map_message) indicates that it is a queue supported by JMS.
    • use the built-in dbms_aqjms package to queue or column messages through PL/SQL.
    • not all features and attributes of advanced queue management can be implemented through the standard JMS interface. The Java package oracle. JMS provides some Oracle extension classes and interfaces that implement the common JMS standard.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.