I want to deploy two instances of the same MDB to process messages from two different Queues under jboss7 with ActiveMQ. So hier is a part of my ejb-jar.xml:
<message-driven>
<ejb-name>FirstInstanceOfMyMDB</ejb-name>
<ejb-class>de.xx.xx.MyMDB</ejb-class>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>activemq/queue/queue_1</activation-config-property-value>
</activation-config-property>
<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>SecondInstanceOfMyMDB</ejb-name>
<ejb-class>de.xx.xx.MyMDB</ejb-class>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>activemq/queue/queue_2</activation-config-property-value>
</activation-config-property>
<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>
With this configuration everything works well.
Now I want to add some instance-specific propeties to each instance: System = A
for FirstInstanceOfMyMDB and System = B
for SecondInstanceOfMyMDB.
I have already tried to use within the to get the System
injected with @Resource
annotation:
<message-driven>
<ejb-name>FirstInstanceOfMyMDB</ejb-name>
...
<env-entry>
<env-entry-name>System</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>A</env-entry-value>
</env-entry>
</message-driven>
<message-driven>
<ejb-name>SecondInstanceOfMyMDB</ejb-name>
...
<env-entry>
<env-entry-name>System</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>B</env-entry-value>
</env-entry>
</message-driven>
But jboss seems to set System
only once either to A or to B. Maybe because the same namespace is used to set the System
.
So My Question: What is the best practice to set custom instance MDB (EJB) Proerties?
Using the approch suggested by user1181247:
@Resource(name="System")
private String System;
I can deploy my MDBs within a ejbmodule with ejb-jar.xml in METH-INF directory and thy work as desired. Tryint to deploy the same classes in a war file with the same ejb-jar.xml in WEB-INF folder I get following exception:
[0m[31m09:13:56,823 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."Server.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."Server.war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "Server.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-8.0.0.Alpha1-SNAPSHOT.jar:8.0.0.Alpha1-SNAPSHOT]
...
Caused by: java.lang.IllegalArgumentException: JBAS011053: Incompatible conflicting binding at java:comp/env/System source: org.jboss.as.ee.component.EnvEntryInjectionSource@1291e
If the env-entry-value is for both instances the same, deploying is done wihout exceptions!
Do I need another/additional configuration for a war file?