The spec should have been clearer. I *think* the spec always *wanted* to
say that it is sufficient for a portable MDB to implement only the
methods of the "message listener interface", but somehow the current
wordings didn't match with the intention. I say this because of two reasons:
1) Session bean class no longer has to implement the interface as long
as it implements the equivalent methods. So, I can't imagine why the
experts would have opted for a different rule for MDB.
2) In section #5.6.3 of the EJB3 core spec, it says "MDB must implement
the methods ...". This statement is not necessary if MDB is required to
implement the listener interface.
Thanks,
Sahoo
Antonio Goncalves wrote:
> Hi,
>
> I have a couple of MDBs that implement MessageListener like that and
> work fine :
>
> @MessageDriven(mappedName = "jms/topic/order")
> public class OrderPrinterBean implements MessageListener {
> }
>
> I was reading a blog
> <http://radio.weblogs.com/0135826/2005/07/22.html> about MDBs and I
> stoped on the following sentence "If you look carefully the MDB does
> not implement the javax.jms.MessageListener interface because I'm
> using the MDB to listen to a JMS provider". I wanted to have a try so
> I got rid of the MessageListener interface and my MDBs still worked. I
> looked at the spec but it's not really clear :
>
> "*5.4.2 The Required Message Listener Interface
> *The message-driven bean class must implement the appropriate message
> listener interface for the messaging type that the message-driven bean
> supports or specify the message listener interface using the
> MessageDriven metadata annotation (...).
>
> The message-driven bean class's implementation of the
> javax.jms.MessageListener
> interface distinguishes the message-driven bean as a JMS
> message-driven bean.
>
> The bean's message listener method (e.g., onMessage in the case of
> javax.jms.MessageListener)
> is called by the container when a message has arrived for the bean to
> service. (...)
>
> If the message-driven bean class implements more than one interface
> other than java.io.Serializable,
> java.io.Externalizable, or any of the interfaces defined by the
> javax.ejb package,
> the message listener interface must be specified by the
> messageListenerInterface element
> of the MessageDriven annotation or the messaging-type element of the
> message-driven
> deployment descriptor element."
>
> Could anybody explain why GlassFish still invokes my MDBs even if they
> don't implement any interface ?
>
> Thanks,
>
> Antonio
>
> PS : Happy new year
>