Sunday, 29 May 2011

Message Driven Bean Annotations for EJB3

The other day, I blogged about the name and mappedName attributes of @Stateless, @Stateful and @MessageDriven annotations of EJB3.

In writing that blog, it occurred to me that it’s very hard to find information on which attributes are available. In the good ol’ days of EJB 2.x, all you had to do was to look at the appropriate EJB schema file and you knew which XML element and attributes did what.

In my experience, the worst of all these annotations is @MessageDriven’s attribute activationConfig and its attendent @ActivationConfigProperty with their very wooley propertyName and propertyValue attributes.

For Weblogic, typical MDB code looks like this:

@MessageDriven(name = "myBasicMDB", mappedName = "jms/BasicTestQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destinationName", propertyValue = "jms/BasicTestQueue") })
public class BasicMessageDrivenBean implements MessageListener etc.

The table below tries to clarify the @ActivationConfigProperty values and determine just exactly what they do:

propertyName propertyValue Description
destinationType javax.jms.Queue or javax.jms.Topic Specifies whether or not this is a queue or topic
destinationName eg. jms/BasicTestQueue Supposedly the JNDI name of the queue or topic, but I couldn't get the MDB to work on Weblogic without the mappedName property set.
acknowledgeMode Dups_ok_acknowledge or Auto_acknowledge This property is used to specify the JMS acknowledgement mode for the message delivery when bean-managed transaction demarcation is used. Defaults to auto-acknowledge.
messageSelector Used to specify the JMS message selector so that messages can be filtered and directed to different beans
subscriptionDurability Durable or NonDurable Used by topics to define whether or not a subscription is durable or non-durable.

I'm of the humble opinion that the table above is incomplete in that EJB2.x allows you to specify a whole bundle of other attributes in your XML files, so I guess that I'll be updating this page as and when I discover other attributes.

No comments: