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;
}
}