Java Reference
In-Depth Information
Chapter 4. Messaging and developing MDBs
This chapter covers
• The basics of message-driven beans (MDBs)
• Sending and receiving messages
@JMSConnectionFactory annotation
JMSContext , JMSConsumer , and JMSProducer classes
In this chapter we'll take a closer look at developing message-driven beans (MDBs). We'll
provide you with an overview of these powerful concepts and show in the context of the
ActionBazaar application how they can be used to solve real-world problems. First, we'll
introduce the fundamental concepts of messaging and then you'll explore the basics of the
Java Messaging Service (JMS) by creating a message producer. We'll then take a look at
MDBs and how EJB 3 simplifies the task of building message consumers.
It's important that you gain an understanding of messaging and JMS before diving into MDB
for two reasons. First, most MDBs you'll see are really souped-up JMS message consumers
implementing JMS interfaces (such as javax.jms.MessageListener ) and using JMS
APIs (such as javax.jms.Message ). Second, for most solutions with MDB, your mes-
saging will involve more than just processing incoming messages.
If you're comfortable with messaging and JMS, feel free to skip to the sections covering
MDBs. But it's always good to reinforce what you know from time to time.
4.1. Messaging concepts
When we talk about messaging in the Java EE context, what we really mean is the process
of sending loosely coupled, asynchronous messages that are transferred in a reliable fashion.
Most communication between components—for example, between stateless session
beans—is synchronous and tightly coupled. The caller directly invokes a method on the re-
cipient bean and waits for the method to finish. Both ends must be present for the commu-
nication to be successful. Messaging is different in that the sender doesn't know when the
message is received and doesn't even directly control who processes the message. In addi-
Search WWH ::




Custom Search