Programming rules for creating MDB

  • MDB class must directly (using implements keyword) or indirectly (using annotation or descriptors) implement a message listener interface. Example,
    • Using implements keyword
      public class QueueListenerMDB implements MessageListener {
    • Using annotation
      @MessageDriven(messageListenerInterface= MessageListener.class)
      public class QueueListenerMDB {
  • It is a POJO class and marked with @MessageDriven annotation
  • The MDB class must be declared as public.
  • The class cannot be either final or abstract.
  • The class must have no-argument constructor. Container uses this constructor to create MDB instance.
  • You must implement the methods defined in message listener interface. The methods must be public and cannot be static or final.
  • You must not throw javax.rmi.RemoteException or any runtime exception. If a RuntimeException is thrown then the MDB instance is terminated.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.