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 messaging 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

4.2. Introducing JMS

4.3. Working with MDBs

4.4. MDB best practices

4.5. Summary