Creating message-driven beans

You can use the Create an Enterprise Bean wizard to create EJB 2.0 or EJB 2.1 message-driven beans.

Message-driven beans were introduced in EJB 2.0 to support the processing of asynchronous messages from a Java™ Message Service (JMS). The EJB 2.1 specification expands the definition of the message-driven bean so that it can support any messaging system, not just JMS. Accordingly, the deployment descriptor elements used to define message-driven beans changed in the EJB 2.1 specification. The wizard for creating an EJB 2.1 message-driven bean also includes additional pages for optionally defining your non-JMS messaging system and its activation configuration elements.

See Message-driven bean deployment descriptor examples for examples of deployment descriptor entries for message-driven beans in the EJB 2.0 and EJB 2.1 specifications.

To create an EJB 2.0 or EJB 2.1 message-driven bean:

  1. In the J2EE perspective, click File > New > Other > EJB > Enterprise Bean. The Create an Enterprise Bean wizard appears.
  2. Select the Message-driven bean radio button.
  3. Select the EJB Component that you want to add the bean to. You can choose EJB 2.0 or EJB 2.1 projects.
  4. In the Bean name field, type the name that you want to assign to the enterprise bean. By convention, bean names should begin with an uppercase letter.
    Note: You can use Unicode characters for the bean name, but Unicode characters are not supported for enterprise bean packages and classes associated with enterprise beans.
  5. In the Source folder field, select the source folder for the new bean.
  6. In the Default package field, enter the package name for the new bean.
  7. Optional: You can select Generated an annotated bean class. If you select this option, the wizard generates annotations at the beginning of the Java code for the bean class. The annotations define the bean's implementation as you specify in the wizard. The annotations are then used by the EJB tools to generate the necessary bean classes, and to provide values that are inserted in the EJB deployment descriptor (ejb-jar.xml). Select this option if you are familiar with annotations and want to use the annotations to update the bean rather than using the deployment descriptor. Other options may not be available if you select this option.

    For more information, see Annotation-based programming overview.

  8. Click Next.
  9. For EJB 2.1 message-driven beans, specify the following:
    1. Specify the messaging service to use for the message-driven bean.
      • JMS type: Select this option if you want to use a JMS messaging service, using the javax.jms.MessageListener class as the listener type.
      • Other type: Select this option if you want to use a non-JMS or custom messaging service. In the Listener type field, enter the fully-qualified name of the listener class.
    2. Click Next.
    3. Specify the details for the message-driven bean.
      Note: If you are creating an EJB 2.1 message-driven bean that uses a non-JMS messaging system, some options are not available but can be defined manually as activation configuration name-value pairs.
      • Transaction type: You can specify that either the container or the bean manages the bean's transactions.
      • Activation Config: Use this table to configure additional properties. Each name-value pair that you define is added to the deployment descriptor as an <activation-config-property> element. For EJB 2.1 message-driven beans that use JMS messaging, the predefined properties include the following:
        acknowledgeMode
        Values include Auto-acknowledge and Dups-ok-acknowledge.
        destinationType
        Values include javax.jms.Queue and javax.jms.Topic.
        messageSelector
        Values are user-specified.
      • Bean class: Enter the desired package and class name for the bean class. By default, the wizard suggests a bean class based on the bean name and default package that you defined. A bean class can be a new class that the wizard generates, or it can be an existing class in the project class path. Click the Class button to open a dialog that lists the classes in the project that correspond to the bean type. The name of the bean class appears blue for existing classes with source. The name of the bean class appears red for existing binary classes.
      • Message Destination Link: Click Browse to link to a message destination. This will add a message-destination-link element to the bean in the deployment descriptor. The message destination link is not available if you selected to generate an annotated bean class.
    4. Click Next.
    5. Optional: In the Bean superclass field, type or select the desired class. This field is disabled if a bean supertype was specified.
    6. Click Finish. The new bean is generated and defined in the deployment descriptor.
  10. For EJB 2.0 message-driven beans, specify the following:
    1. Specify the details for the message-driven bean. Note: JMS-type messaging is implied for all 2.0 message-driven beans.
      • Transaction type: You can specify that either the container or the bean manages the bean's transactions.
      • Acknowledge mode: For bean-managed transactions, you can specify how the session acknowledges any messages it receives. Choices are Auto-acknowledge and Dups-ok-acknowledge.
      • Message-driven destination: Select a Destination type of Queue or Topic:
        • Queue specifies that the point-to-point JMS messaging model will be used.
        • Topic specifies that the publish-and-subscribe JMS messaging model will be used.
      • Durability: If you selected a message destination type of Topic, you can specify whether a topic subscription is durable or non-durable:
        • Durable: A subscriber registers a durable subscription with a unique identity that is retained by JMS. Subsequent subscriber objects with the same identity resume the subscription in the state it was left in by the earlier subscriber. If there is no active subscriber for a durable subscription, JMS retains the subscription's messages until they are received by the subscription or until they expire.
        • NonDurable: The subscriptions last for the lifetime of their subscriber object. This means that a client sees the messages published on a topic only while its subscriber is active. If the subscriber is not active, the client is missing messages published on its topic.
      • Bean class: Enter the desired package and class name for the bean class. By default, the wizard suggests a bean class based on the bean name and default package that you defined. A bean class can be a new class that the wizard generates, or it can be an existing class in the project class path. Click the Class button to open a dialog that lists the classes in the project that correspond to the bean type. The name of the bean class appears blue for existing classes with source. The name of the bean class appears red for existing binary classes.
      • Message selector: The JMS message selector is used to determine which messages the message bean receives.
    2. Click Next.
    3. Optional: In the Bean superclass field, type or select the desired class. This field is disabled if a bean supertype was specified.
    4. Click Finish. The new bean is generated and defined in the deployment descriptor.
You can use the Bean page of the EJB Deployment Descriptor editor to review the bean and change or add any additional settings or extensions and bindings.

Feedback