jsr343-experts@jms-spec.java.net

[jsr343-experts] Re: [jms-spec issues] [JIRA] Created: (JMS_SPEC-54) Define a standard way to configure the destination on which a MDB consumes messages

From: Adam Bien <abien_at_adam-bien.com>
Date: Mon, 7 Nov 2011 17:46:43 +0100

++1 (JNDI-mapping is the common case)
On 21.10.2011, at 19:14, Nigel Deakin (JIRA) wrote:

> Define a standard way to configure the destination on which a MDB consumes messages
> -----------------------------------------------------------------------------------
>
> Key: JMS_SPEC-54
> URL: http://java.net/jira/browse/JMS_SPEC-54
> Project: jms-spec
> Issue Type: Improvement
> Reporter: Nigel Deakin
>
>
> 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.
>
> h3. Review of existing specification (EJB 3.1)
>
> 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}}:
>
> {noformat}
> <message-driven>
> <ejb-name>ExpenseProcessing</ejb-name>
> <ejb-class>com.wombat.empl.ExpenseProcessingBean</ejb-class>
> <messaging-type>javax.jms.MessageListener</messaging-type>
> ...
> <message-destination-type>javax.jms.Queue</message-destination-type>
> <message-destination-link>ExpenseProcessingQueue</message-destination-link>
> ...
> </message-driven>
> {noformat}
>
> h3. Issues with the existing specification
>
> This raises the following questions:
>
> h4. 1. What is <message-destination-link>?
>
> 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}}:
>
> {noformat}
> <ejb-jar>
> <enterprise-beans>
> <message-driven>
> <display-name>MDB1</display-name>
> <ejb-name>MessageBean</ejb-name>
> <messaging-type>javax.jms.MessageListener</messaging-type>
> <transaction-type>Container</transaction-type>
> <message-destination-type>javax.jms.Queue</message-destination-type>
> <message-destination-link>MsgBeanInQueue</message-destination-link>
> </message-driven>
> </enterprise-beans>
> <assembly-descriptor>
> <message-destination>
> <lookup-name>jms/inboundQueue</lookup-name> <!---
> <message-destination-name>MsgBeanInQueue</message-destination-name>
> </message-destination>
> </assembly-descriptor>
> </ejb-jar>
> {noformat}
>
> 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.
>
> h4. 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 {{_at_Resource(lookup="jms/foo")}} declaration for managed connections.
>
> h4. 3. Can I define the message destination reference for a MDB using annotation?
>
> No, there is equivalent to {{<message-destination-link>}} using annotation.
>
> h4. 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 {{_at_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 {{_at_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.
>
> h3. Proposals:
>
> 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>}}:
>
> {noformat}
> <ejb-jar>
> <display-name>Ejb1</display-name>
> <enterprise-beans>
> <message-driven>
> <display-name>MDB1</display-name>
> <ejb-name>MessageBean</ejb-name>
> <message-destination-type>javax.jms.Queue</message-destination-type>
> <message-destination-jndi-name>jms/inboundQueue<message-destination-jndi-name>
> ...
>
> {noformat}
>
> 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 {{_at_MessageDriven}} annotation, called {{message-destination-jndi-name}}. For example:
>
> {noformat}
> MessageDriven(message-destination-jndi-name="jms/inboundQueue")
> public class MyMDB implements MessageListener {
> ....
> {noformat}
>
> C. *It is proposed* that the {{_at_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 {{message-destination-link"}}
>
> {noformat}
> MessageDriven(message-destination-link="ExpenseProcessingQueue")
> public class MyMDB implements MessageListener {
> ....
> {noformat}
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators: http://java.net/jira/secure/Administrators.jspa
> -
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>