Creating JMS destination programatically in JBoss
One of our clients wanted to create a queue programaticly in JBoss environment. JMS provides a mechanism to create temporary queue using javax.jms.Session api. However the spec states that “"The physical creation of queues is an administrative task and is not to be initiated by the JMS API. The one exception is the creation of temporary queues, which is accomplished with the createTemporaryQueue method. ".
Nevertheless, the customer wanted its queue to be not “temporary” (due to internal constraints). Constructing non-temporary queue can be done with JBoss specific management api. JBoss can use three different JMS providers (depend on which JBoss version you use). The latest and greatest is HornetQ - its manual it is explained how to do it - Please read here. Nonetheless, JBoss-Messaging also provides such api - Please see here.

Comments
with activemq for example you don't have to do anything special.
from AMQ docs:
"In ActiveMQ you do not have to create destinations up front before you can use them. The ActiveMQ broker auto-creates the physical resources associated with a destination on demand (i.e. when messages are sent to a new destination on a broker).
This means that a client can create a new Queue or Topic dynamically either by
* calling createQueue() or createTopic() on a JMS Session
* creating an instance of ActiveMQTopic or ActiveMQQueue and possibly registering them in JNDI
and the broker will automatically create the physical destinations for you. This avoids spending large amounts of time creating every individual destination you wish to use and possibly then exposing it in some JNDI provider."
of course you can disable this behaviour.
http://activemq.apache.org/how-do-i-create-new-destinations.html
Thanks Yanai!
The client still has 2 questions tho:
1. What can be done in the even earlier version - JBossMQ?
2. Actually they're more concerned with the pool of MDB workers & less with the queue. Can the MDB be created dynamically just in-case the deployment requires it? (I guess it could be stopped dynamically, but they would like to not create it in the 1st place).
Thanks..
I'll split my answer into two parts: Regarding the ability to create queue with JBossMQ you can do it with DestinationManager Mbean. It is the main JMS service in JBossMQ and you can use it to create and destroy queues and topics at runtime. To create queue , please look at createQueue.
Regarding the MDB control instances - In JBoss there is one instance of the
Containercreated for each unique configuration of an EJB, which is deployed by the the EJBDeployer. Thus, you can configure the minimum size in its “container-pool-conf” element :<jboss> ... <container-configurations> ... <container-configuration> ... <container-pool-conf> <MaximumSize>20</MaximumSize> <MinimumSize>0</MinimumSize> <strictMaximumSize>true</strictMaximumSize> </container-pool-conf> ... </container-configuration> ... </container-configurations> ... </jboss>