Creating a message-driven bean using annotations

You can use Java™ EE annotations to create a message-driven bean and add it to your project.

Before you begin

You must have a Java project, an EJB project, or a web project created in your workspace.

About this task

The main difference between a message-driven bean and a session bean is that a message-driven bean has no local or remote interface. Instead, it has only a bean class.

Procedure

  1. In the Java EE perspective, click File > New > Class.
  2. In the Source folder field, select the source folder for the new bean.
  3. In the Default package field, type the package name for the new bean, and click Finish.
  4. In the Java class editor, underneath the package declaration, type @MessageDriven. You can see an error / quick fix icon quick fix icon next to the @MessageDriven line.
    Tip: You can simply type @Mess and then press CTRL+Spacebar to see the options in content assistance:
    Content Assist Message-driven bean
  5. You can see an error / quick fix icon quick fix icon next to the @MessageDriven line. Right click the quick fix icon and select Quick Fix:
    Quick Fix Message-Driven bean
  6. Select @MessageDriven(EJB) and the tools automatically add the dependency import javax.ejb.MessageDriven;.
  7. In the Enterprise Explorer view, expand your <Java project_name> > ejbModule, and your new message-driven bean Java class is listed under its package name.
  8. You can use the @MessageDriven annotation to specify properties for the bean, including
    • Destination type
    • A durable subscription
    • A message selector
    • An acknowledgment mode
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: tcreatingmessdrivbeans.html