Eclipse + JBoss 5 + EJB3 Development Guide (14): Message-driven beans

Source: Internet
Author: User
Tags message queue jboss

The Sessionbean examples given in the previous article are all synchronous calls to the Sessionbean method, that is, only when the code in the method has finished executing, can it be returned to the client. In some cases, however, because the Sessionbean method takes longer to execute, this requires that the method be called asynchronously, otherwise the client will have to wait for a longer period of time. To implement an asynchronous invocation, you need to use the message-driven bean that you want to talk about. The rationale for message-driven beans is that after a client sends a message to the message server, the message server saves the message in the message queue. At this point, a consumer in the message server (the object that reads and processes the message) reads the message and processes it. The client that sends the message is called the message producer.

The basic function of the message-driven bean example given in this article is that the client sends a message to the message server (the message is actually an object instance of an entity bean), and then the message consumer reads the message to persist the entity bean in the message. The steps for implementing a message-driven bean are as follows:

I. Implementing entity BEANS

Package entity;

Import java.io.Serializable;
Import java.util.Date;
Import Javax.persistence.Column;
Import javax.persistence.Entity;
Import Javax.persistence.GeneratedValue;
Import Javax.persistence.GenerationType;
Import Javax.persistence.Id;
Import javax.persistence.Table;

@Entity
@Table (name= "t_date") Public
class Datebean implements Serializable
{
private int id;<    c14/> private Date mydate;
@Id
@GeneratedValue (strategy=generationtype.identity) public
int getId ()
{
return    ID;
The public
void setId (int id)
{
this.id = ID;
@Column (name= "mydate") public
Date getmydate ()
{return
mydate;
The public
void Setmydate (Date mydate)
{
this.mydate = mydate;
}

}        

Related Article

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.