Chapter 26. JMS User’s Guide
209
}
This method sends a message containing its String argument.
26.6.2. The Entity Bean
The example uses the simple Entity Bean Account for writing data into a database. Refer to the sample
eb, which is described in Chapter 2
Getting Started with JOnAS
and in the
JOnAS Tutorial
.
26.6.3. The Client Application
The client application calls the sendMsg method of the EjbComp bean and creates an AccountImpl
Entity Bean, both within the same transaction.
public class EjbCompClient {
...
public static void main(String[] arg) {
...
utx = (UserTransaction)
initialContext.lookup("javax.transaction.UserTransaction");
...
home1 = (EjbCompHome) initialContext.lookup("EjbCompHome");
home2 = (AccountHome) initialContext.lookup("AccountImplHome");
...
EjbComp aJmsBean = home1.create();
Account aDataBean = null;
...
utx.begin();
aJmsBean.sendMsg("Hello commit"); // sending a JMS message
aDataBean = home2.create(222, "JMS Sample OK", 0);
utx.commit();
utx.begin();
aJmsBean.sendMsg("Hello rollback"); // sending a JMS message
aDataBean = home2.create(223, "JMS Sample KO", 0);
utx.rollback();
...
}
}
The result of this client execution will be that:
•
The
"Hello commit"
message will be sent and the
[222, ’JMS Sample OK’, 0]
record will
be created in the database (corresponding to the Entity Bean
109
creation).
•
The
"Hello rollback"
message will never be sent and the
[223, ’JMS Sample KO’, 0]
record will not be created in the database (since the Entity Bean
110
creation will be canceled).
26.6.4. A Pure JMS Client for Receiving Messages
In this example, the messages sent by the EJB component are received by a simple JMS client that is
running outside the JOnAS server, but listening for messages sent on the JMS topic "sampleTopic." It
uses the ConnectionFactory automatically created by JOnAS named "JCF".
public class MsgReceptor {
static Context ictx = null;
Summary of Contents for Application Server
Page 1: ...Red Hat Application Server JOnAS User Guide ...
Page 8: ......
Page 22: ...14 Chapter 1 Java Open Application Server JOnAS a J2EE Platform ...
Page 58: ...50 Chapter 3 JOnAS Configuration ...
Page 66: ...58 Chapter 5 JOnAS Class Loader Hierarchy ...
Page 78: ...70 Chapter 6 JOnAS Command Reference ...
Page 80: ......
Page 86: ...78 Chapter 7 Developing Session Beans ...
Page 136: ...128 Chapter 9 Developing Message Driven Beans ...
Page 142: ...134 Chapter 10 Defining the Deployment Descriptor ...
Page 148: ...140 Chapter 11 Transactional Behavior of EJB Applications ...
Page 158: ...150 Chapter 14 EJB Packaging ...
Page 162: ...154 Chapter 15 Application Deployment and Installation Guide ...
Page 164: ......
Page 176: ...168 Chapter 18 WAR Packaging ...
Page 178: ......
Page 184: ...176 Chapter 20 Defining the Client Deployment Descriptor ...
Page 186: ...178 Chapter 21 Client Packaging ...
Page 188: ......
Page 192: ...184 Chapter 23 EAR Packaging ...
Page 194: ......
Page 200: ...192 Chapter 24 JOnAS Services ...
Page 204: ...196 Chapter 25 JOnAS and the Connector Architecture ...
Page 222: ...214 Chapter 27 Ant EJB Tasks Using EJB JAR ...
Page 234: ...226 Chapter 29 Web Services with JOnAS ...
Page 236: ......
Page 260: ...252 Chapter 34 How to use Axis in JOnAS ...
Page 270: ...262 Chapter 36 Web Service Interoperability between JOnAS and BEA WebLogic ...
Page 296: ......