"Advanced EJB" in-depth discussion of three kinds of beans (iii.)--messagedriven Bean

Source: Internet
Author: User

Through the first two articles

"Advanced EJB" in-depth discussion of three kinds of bean (a)--session bean

"Advanced EJB" to explore three kinds of Bean (ii)--entity Bean

The first two beans have been introduced, and today we continue to introduce the third type of bean--messagedriven bean.


To say Messagedriven beans before you introduce the JMS (Java Message Service), JMS is the Java messaging Services, it is a platform-independent API (application program Interface Application interface), a technical specification for message-oriented middleware on the Java platform that facilitates the message exchange of Java applications in a messaging system and simplifies the development of enterprise applications by providing a standard interface for generating, sending, and receiving messages. The Messagedriven Bean is based on a JMS message and can only accept JMS messages sent by the client and then process. Knowing this, we continue to understand messagedriven beans.


The Messagedriven bean, the message-driven bean, is designed to specifically handle message-based requests. Message-driven beans have the ability to handle a large number of concurrent messages, and if a message executes for a long time without real-time feedback from the user, it is also a good fit to use a message-driven bean, which avoids the client waiting for a method call for a long time until the result is returned. For example, when the order is successful, send an email or SMS to the user.


There are two working models for JMS: Peer-point-to-point model and PUB/SUB release subscription model.

Peer (point-to-point) point-to-point model , what is a peer model? The peer model has senders, receivers, and message queues. Each message has only one consumer, that is, once the message is consumed, the message is no longer in the message queue, the sender and receiver of the message does not have a dependency on time, that is, when the sender sends the message, regardless of whether the recipient is running, it does not affect the message being sent to the queue The recipient will need to answer the queue successfully after receiving the message successfully; Each message is sent to a specific message queue, the recipient obtains the message from the message queue, and the message queue retains the message until they are consumed or timed out.

When is the right time to use peer-to? Is that if you want to send every message can be successfully processed, then you need to apply the peer-to model.


pub/sub (Publish/subscribe) Publish/subscribe model, What is the Pub/sub publish/subscribe model? There are themes, publishers, subscribers in the PUB/SUB model. The client sends a message to the subject, and multiple publishers send the message to the topic, which the system passes to multiple subscribers. Each of these messages can have more than one consumer, and there is a time-dependent relationship between the Publisher and the Subscriber, who must establish a subscription before they can consume the publisher's message, and in order to consume the message, the Subscriber must remain in the running state.

When is the right time to use Pub/sub? If you want to send a message that can be processed without any processing, or handled by a consumer, or can be processed by multiple consumers, you can use the PUB/SUB model.



Today this article is introduced here, through the previous articles on EJB, we have a general understanding of EJB, in the next Itoo project we will use EJB, so look forward to in practice, EJB has a more comprehensive understanding. The article about EJB is introduced here briefly, and I will update my blog in time when I have a new understanding of EJB in the project. Next I will write some articles about SPRIGMVC, please look forward to it!

"Advanced EJB" in-depth discussion of three kinds of beans (iii.)--messagedriven Bean

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: info-contact@alibabacloud.com 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.