Controlling order of deployment on JBoss in EAP 4.x
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 4.x
Issue
-
We have a problem in our application were the message listeners (MDBs) are started even before the some of the application ejbs are deployed and they start consuming the messages. And MDBs logic start looking up for the EJBs resulting into failure.
Do we have any option by which, we can tell the application server to deploy and start MDBs in an EAR as last.
We have a similar feature in Websphere where we can set priority for each of the modules (EJB, MDB and War) in an Ear application. This way the container starts the least priority modules as the last.
-
I wish to have the jmx-console.war deployed after my application's ear. I found that I can override the deployment order by changing the EnhancedSuffixOrder in org.jboss.deployment.MainDeployer-xmbean.xml, but I don't want to set all war applications to be deployed last; just the JMX Console.
- Our developers need a ha-singleton service be deployed as the last one, after all other ears are already started.
They've found a way to achieve that, by moving cluster/deploy-hasingleton-jboss-beans.xml file to deploy.last directory. Is this the correct way?
Resolution
Yes, the deployment order is controllable.
It's up to your personal preference which method you want to use. Generally speaking if there are only a small number of dependencies you might want to explicitly state them with a <depends> clause, but if there are many then it is probably easier to set up a general rule.
Filename based ordering
Default order of deployment
- deployer
- -deployer.xml
- sar
- -service.xml
- rar
- -ds.xml
- har
- jar
- war
- wsr
- ear
- zip
- bsh
- last
The DeploymentSorter can be changed by changing the configuration in $JBOSS_HOME/server/$PROFILE/conf/jboss-service.xml [EAP 4.3 / EAP 4.2]
-
org.jboss.deployment.scanner.PrefixDeploymentSorter
- The PrefixDeploymentSorter examines the first characters of the file name to find packages that begin with numbers. Files that do not start with numbers are deployed first according to the roles of the generic DeploymentSorter. The remaining deployments, which do begin with numbers are then deployed in numeric order. For example, the deployment
20foo.war
will be deployed before100bar.sar
even though the SAR file would normally deploy before the WAR file.
- The PrefixDeploymentSorter examines the first characters of the file name to find packages that begin with numbers. Files that do not start with numbers are deployed first according to the roles of the generic DeploymentSorter. The remaining deployments, which do begin with numbers are then deployed in numeric order. For example, the deployment
-
org.jboss.deployment.scanner.AlphaNumericDeploymentSorter
- The AlphaNumericDeploymentSorter extends the PrefixDeploymentSorter and resolves the occasional problem of deployments working on windows and not unix (or vise versa). This problem originally stems from the way File.list() returns the list of files in a different order depending on platform. So when doing the compare() for the Collections.sort() in the URLDeploymentScanner, if both the prefix and the file type are the same, leave it in the same order (which will have already been sorted by the File.list() call). Hence the problem between platforms. The AlphaNumericDeploymentSorter adds a final comparison of the file names using the String class' compareToIgnoreCase() method.
Going with a Deploymentsorter based method as described in the links you can use names, numeric prefixes, or write your own DeploymentSorter to use any criteria you prefer including reading a config file specifying the exact order (but make sure it handles deployment not on the list too).
Please see the instructions on our wiki here:
[1] http://www.jboss.org/community/wiki/urlcomparator
[2] http://www.jboss.org/community/wiki/MainDeployerEnhancedSuffixOrder
Using explicit dependencies
An alternate way to control deployment order is to set dependencies in the deployment descriptors (jboss.xml in most cases) like this:
<depends>jboss:service=TransactionManager</depends>
or to depend on one of your own file deployments like this:
<depends>jboss.j2ee:url=<your-ear-name-here>,service=EARDeployment</depends>
See here for more information the <depends> tag.
Components of the same EAR
If all components involved are in the same EAR, you can also put this in ear/META-INF/jboss-app.xml
<module-order>strict</module-order>
It will make jboss deploy things in the order they appear in the application.xml.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments