Here a nice page where you can see the versions used in JBoss EAP:
https://access.redhat.com/articles/112673
Unfortunately not very up2date. I use EAP 6.4.4 but the table ends with EAP 6.4.0.
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Here a nice page where you can see the versions used in JBoss EAP:
https://access.redhat.com/articles/112673
Unfortunately not very up2date. I use EAP 6.4.4 but the table ends with EAP 6.4.0.
Sometimes you have the need to start only one MessageDrivenBean (MDB) to process the messages of a queue. One reason could be that the order of the message matters. And if you would process them with more than one instance the order you process them is not guaranteed. Per default the MDB are linked with a bean pool of 20 instances.
But you cannot annotate a MDB with @Singleton, so you have to create a specific bean pool and associate your MDB with this pool.
First of all, add the needed annotations to your project:
<dependency> <groupId>org.jboss.ejb3</groupId> <artifactId>jboss-ejb3-ext-api</artifactId> <version>2.2.0.Final</version> </dependency>
After add an additional instance pool to our JBoss:
Via CLI:
/subsystem=ejb3/strict-max-bean-instance-pool=single-instance-pool:add(max-pool-size=1,timeout=5,timeout-unit=MINUTES)
Or simply add the following lines to your standalone-full.xml
<pools> <bean-instance-pools> <strict-max-pool name="slsb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/> <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/> <strict-max-pool name="single-instance-pool" max-pool-size="1" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/> </bean-instance-pools> </pools>
And as last step, link your MDB with the created pool:
@Pool("single-instance-pool") @MessageDriven( activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/ExpiryQueue") }, mappedName = "jms/queue/ExpiryQueue") public class SingletonMdb implements MessageListener { private static final Logger logger = getLogger(SingletonMdb.class); @Override public void onMessage(Message message) { TextMessage tm = (TextMessage) message; try { String text = tm.getText(); logger.info("Message received: {}", text); } catch (JMSException e) { logger.error("Error occured: ", e); } } @PostConstruct public void postConstruct() { logger.info("instance created {}", this.toString()); } }
You find a complete example on github: https://github.com/erard22/singleton-mdb-example
Just clone and execute the following steps:
For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-full.xml
For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-full.xml
mvn clean package wildfly:execute-commands
mvn clean package wildfly:execute-commands wildfly:deploy
http://localhost:8080/singleton-mdb-example/rest/message/test
Doing it several times you will se in the console that the bean is only created once even if there would be concurrent requests:
22:08:46,138 INFO [ch.erard22.ee.messaging.mdb.SingletonMdb] (Thread-38 (HornetQ-client-global-threads-2080930476)) instance created ch.erard22.ee.messaging.mdb.SingletonMdb@1d9c36c9 22:08:46,138 INFO [ch.erard22.ee.messaging.mdb.SingletonMdb] (Thread-38 (HornetQ-client-global-threads-2080930476)) Message received: test 22:08:51,719 INFO [ch.erard22.ee.messaging.mdb.SingletonMdb] (Thread-45 (HornetQ-client-global-threads-2080930476)) Message received: test 22:08:53,554 INFO [ch.erard22.ee.messaging.mdb.SingletonMdb] (Thread-44 (HornetQ-client-global-threads-2080930476)) Message received: test 22:08:54,891 INFO [ch.erard22.ee.messaging.mdb.SingletonMdb] (Thread-45 (HornetQ-client-global-threads-2080930476)) Message received: test 22:08:55,930 INFO [ch.erard22.ee.messaging.mdb.SingletonMdb] (Thread-44 (HornetQ-client-global-threads-2080930476)) Message received: test