Developing an enterprise application to use message-driven beans

Applications can use message-driven beans as asynchronous message consumers. You deploy a message-driven bean as a message listener for a destination. The message-driven bean is invoked by an activation specification or a JMS listener when a message arrives on the input destination that is being monitored.

About this task

You develop an enterprise application to use a message-driven bean as with any other enterprise bean, except that a message-driven bean does not have a home interface or a remote interface.

You should develop your message-driven bean to delegate the business processing of incoming messages to another enterprise bean, which provides clear separation of message handling and business processing. This separation also means that the business processing can be invoked either by the arrival of incoming messages or, for example, by a WebSphere® J2EE client. Responses can be handled by another enterprise bean acting as a sender bean, or they can be handled in the message-driven bean.

EJB 2.0 message-driven beans support only Java™ Message Service (JMS) messaging. EJB 2.1 and EJB 3 message-driven beans can support other messaging types in addition to JMS. All message-driven beans must implement the MessageDrivenBean interface. For JMS messaging, a message-driven bean must also implement the message listener interface javax.jms.MessageListener. Other Java EE Connector Architecture (JCA)-compliant resource adapters might provide their own message listener interfaces that must be implemented.

Procedure

  1. Create the Enterprise Application project.
  2. Create the message-driven bean class.

    You can use the New Enterprise Bean wizard of Rational® Application Developer to create an enterprise bean with a bean type of Message-driven bean. The wizard creates appropriate methods for the type of bean.

    By convention, the message bean class is named nameBean, where name is the name you assign to the message bean; for example:
    public class MyJMSppMDBBean implements MessageDrivenBean, javax.jms.MessageListener

    For more information, see Example: Creating the message-driven bean class and Creating a message-driven bean in the Rational Application Developer help bookshelf.

    The result of this step is a message-driven bean that can be assembled into an EAR file for deployment.
  3. Optional: Use the EJB deployment descriptor editor to review and, if needed, change the deployment attributes. You can use the EJB deployment descriptor editor to review deployment attributes that you specified on the EJB creation wizard (such as Transaction type and Message selector) and other default deployment attributes.

    If needed, you can override the values of these attributes later, after the enterprise application has been exported into an EAR file for deployment, as described in Configuring deployment attributes for a message-driven bean against JCA 1.5-compliant resources and Configuring deployment attributes for a message-driven bean against a listener port.

    1. In the property pane, select the Beans tab.
    2. Under General deployment attributes, configure the Transaction type attribute.

      This attribute determines whether the message-driven bean manages its own transactions, or whether the container manages transactions on behalf of the bean.

      Bean
      The message-driven bean manages its own transactions.
      Container
      The container manages transactions on behalf of the bean.
    3. Specify advanced deployment attributes.

      Under Activation Configuration, review the following attributes:

      Acknowledge mode
      This attribute determines how the session acknowledges any messages it receives.
      Auto Acknowledge
      The session automatically acknowledges delivery of each message.
      Dups OK Acknowledge
      The session lazily acknowledges the delivery of messages. This setting is likely to result in the delivery of some duplicate messages if JMS fails, so it should be used only by consumer applications that are tolerant of duplicate messages.
      For more information about this attribute, see Message-driven bean deployment descriptor attributes.
      Destination type
      This attribute determines whether the message bean uses a queue or topic destination.
      Queue
      The message bean uses a queue destination.
      Topic
      The message bean uses a topic destination.
      Durability
      This attribute determines whether a JMS topic subscription is durable or nondurable.
      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 messages until they are received by the subscription or until they expire.
      Nondurable
      Nondurable 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.

      A nondurable subscriber can only be used in the same transactional context (for example, a global transaction or an unspecified transaction context) that existed when the subscriber was created. For more information about this context restriction, see Transaction context impact on non-durable subscribers.

      Message selector
      This attribute determines the JMS message selector that is used to select which messages the message bean receives. For example:
      JMSType='car' AND color='blue' AND weight>2500

      The selector string can refer to fields in the JMS message header and fields in the message properties. Message selectors cannot reference message body values.

    4. Specify bindings deployment attributes.

      Under WebSphere Bindings, select the JCA Adapter option then specify the bindings deployment attributes:

      ActivationSpec JNDI name
      This attribute specifies the JNDI name of the activation specification that is used to deploy this message-driven bean. This name must match the name of an activation specification that you define to WebSphere Application Server.
      ActivationSpec Authorization Alias
      This attribute specifies the name of an authentication alias used for authentication of connections to the JCA resource adapter. An authentication alias specifies the user ID and password that is used to authenticate the creation of a new connection to the JCA resource adapter.
      Destination JNDI name
      This attribute specifies the JNDI name that the message-driven bean uses to look up the JMS destination in the JNDI namespace.
  4. Assemble and package the application for deployment.

Results

The result of this task is an EAR file, containing the message-driven bean, for the enterprise application that can be deployed in WebSphere Application Server.

What to do next

After you have developed an enterprise application to use message-driven beans, configure and deploy the application. For example, define activation specifications for the message-driven beans and, optionally, change the deployment descriptor attributes for the application. For more information, see Deploying an enterprise application to use message-driven beans with JCA 1.5-compliant resources and Deploying an enterprise application to use message-driven beans with listener ports.



In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic    

Terms of Use | Feedback

Last updated: Oct 21, 2010 3:36:59 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=compass&product=was-express-iseries&topic=tmb_devap
File name: tmb_devap.html