This is a request for the JMS and/or EJB specifications to improve the way in which specify how an application or deployer may specify the destination from which a JMS message-driven bean to receive messages. There are several significant omissions from the specification which need to be rectified.
Although MDBs are specified in the EJB specification, this request should be considered first by the JMS 2.0 expert group who may then want to raise it with the EJB 3.2 expert group.
In the EJB 3.1 specification, Section 16.9 "Message Destination References" states that the destination used by a JMS message-driven bean can be specified using the <message-destination-link> element of the <message-driven> element in ejb-jar.xml:
This raises the following questions:
The <message-destination-link> element defines the destination from which the MDB consumes messages in terms of a "message destination reference".
The purpose of "message destination references" is to allow an application which sends messages to a particular destination and also consumes from the same destination to inform the deployer of this fact without having to actually specify the name (or JNDI name) of the destination.
As stated above, a MDB can specify the "message destination reference" of the destination from which it consumes messages using a <message-destination-link> element under the <message-driven> element. Another component (e.g. a session bean or another MDB) can specify the destination to which it sends messages using a <message-destination-link> element under a <message-destination-ref> element. If these two elements contain the same string then the deployer knows they refer to the same queue or topic.
A message destination reference is not the JNDI name of the queue or topic. It is just a logical name. It can be mapped to an actual JNDI name using the <assembly-descriptor> element in ejb-jar.xml as follows:
Here's how ejb-jar.xml could be used to define a MDB as consuming messages from a "message destination reference" called MsgBeanInQueue which was mapped to a JNDI name jms/inboundQueue:
A message destination reference can typically also be mapped to an actual JNDI name using the application-server-specific deployment descriptor, though by definition this is beyond the scope of the EJB specification.
2. Is that the only way you can define the destination on which a MDB consumes messages in ejb-jar.xml? Can you define its JNDI name directly without bothering with references?
No, the EJB specification doesn't mention any way to define the destination in ejb-jar.xml apart from using the <message-destination-link> element of ejb-jar.xml. In particular it doesn't define any way to define its JNDI name directly, analogous to using either the JNDI API or a @Resource(lookup="jms/foo") declaration for managed connections.
No, there is equivalent to <message-destination-link> using annotation.
4. Can I define the JNDI name of the destination on which a MDB consumes messages directly using annotation?
No, there is no way to define this using annotation, analogous to using a @Resource(lookup="jms/foo") declaration when using the JMS API directly.
So, what seems to be missing?
A. As explained in (2) and (4) above, there isn't a standard way for MDB applications to short-circuit the use of message destination references and define the JNDI name of the destination from which a JMS message-driven bean consumes messages, either using ejb-jar.xml or annotations. This contrasts with EJBs which send messages, where the JNDI name of the destination can be specified in the MDB code using the JNDI API or a @Resource(lookup="jms/foo") declaration.
B. As explained in (3) above, there is no standard way for the application to define using annotation the "message destination reference" on which the JMS message-driven bean is consuming messages.
A. It is proposed that the <message-driven> element in ejb-jar.xml be extended to define an additional sub-element which can be used to specify the JNDI name of the destination from which a JMS message-driven mean consumes messages. A suggested element name is <message-destination-jndi-name>:
It might be asked why this needs to be defined by a new subelement of <message-driven> rather than, say, a new standard activation configuration property. The answer is that the way that the JNDI name is defined needs to be consistent with the way that the message destination reference is defined, which is by the <message-destination-link> subelement of <message-driven>
B. It is proposed that the equivalent annotation be a new attribute of the @MessageDriven annotation, called messageDestinationJndiName. For example:
C. It is proposed that the @MessageDriven annotation be extended to allow applications to define the "message destination reference" on which the JMS message-driven bean is consuming messages, using a new attribute messageDestinationLink"