Writing a message-driven bean: your job as Bean Provider

image with no caption

You put THREE kinds of methods in the bean class:

  1. Bean Law: ejbCreate() method

    Write a single, no-argument ejbCreate() method in the bean. It doesn’t match anything or come from any interface. It’s there because it MUST be.

  2. MessageListener implementation: onMessage()

    This is your business method. Your only business method.

    <<interface>>

    MessageListener

    onMessage()

  3. MessageDrivenBean implementation: container callbacks

    Implement both of the methods from the MessageDrivenBean interface, which your bean must implement in the official Java way (i.e. using the ‘implements MessageDrivenBean’ declaration either in your bean class or one of its superclasses)

    <<interface>>

    MessageDrivenBean

    ejbRemove()

    setMessageDrivenContext()

Rules for the message-driven bean class

  1. The class must implement javax.ejb.MessageDrivenBean and javax.jms.MessageListener.

    public class ...

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.