I'm using EJB 3.1 and I want to configure an MDB to listen to multiple queues.
I'd prefer defining the queue names via XML but the other definitions via annotations.
Can this be done?
Asked
Active
Viewed 8,565 times
4
2 Answers
7
Once instantiated, an MDB can only listen to the resource specified in their destination ActivationConfigProperty, however you can create multiple instances of the same MDB with different destinations (queues, in your case).
Create two entries in your ejb-jar.xml with different destination and ejb-name properties, but the same ejb-class.

jpredham
- 2,149
- 1
- 23
- 37
-
Hi jperdham, thanks for your answer. You mean I should define all the properties I want via the ActivationConfigProperty annotations and have just the destination and ejb-name differently defined in the ejb-jar.xml? – Ittai Aug 25 '11 at 07:44
-
Hey Ittai, you can put ActivationConfigProperty's in either ejb-jar.xml OR in annotations, it's really up to you where you put your properties. If you have a set of properties that you change a lot or on a machine-by-machine basis it's easier to change them in xml than to create a new build of your application. – jpredham Aug 25 '11 at 14:45
0
use ejb-jar.xml instead of ibm-ejb-jar-bnd.xml
<message-driven>
<ejb-name>MessageDrivenBean1</ejb-name>
<ejb-class>com.sample.MessageDrivenBean</ejb-class>
<messaging-type>javax.jms.MessageListener</messaging-type>
<transaction-type>Container</transaction-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
<message-driven>
<ejb-name>MessageDrivenBean2</ejb-name>
<ejb-class>com.sample.MessageDrivenBean</ejb-class>
<messaging-type>javax.jms.MessageListener</messaging-type>
<transaction-type>Container</transaction-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
And remove @MessageDriven annotation from your Java class
'@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})'

JM Galicia
- 1
- 1