We use a service orientated architecture approach where we have some core services used by other services. On startup, our services usually load up a cache of data from the core services so that it's available when a request comes in or scheduled tasks run.
I'm using Wildfly 8.2.0 and have Project A which depends on Project B (both are .war's). Project A needs to wait for Project B to be loaded in order to start up.
Here is jboss-deployment-structure.xml in project B:
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<module-alias name="deployment.projectB"/>
</deployment>
</jboss-deployment-structure>
On a side note, module-alias
is used because project B is a war with a name like "projectB-2.0.0.war" but I don't want to care about the version number when I specify the dependency.
Here is jboss-deployment-structure.xml in project A:
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="deployment.projectB" />
</dependencies>
</deployment>
</jboss-deployment-structure>
What I would like: if A and B are on the same Wildfly server, A needs to wait for B to start. If A and B are on separate servers, they should start immediately.
Would optional dependencies accomplish this? Like:
<dependencies>
<module name="deployment.projectB" optional="true" />
</dependencies>
Update
I just set up optional="true"
with A and B on the same server, and in this test, A and B are starting up at the same time (in the logs, I'm seeing EJB JNDI bindings being listed in pretty random order: B, A, B, B, B, B, B, A, A). By "JNDI bindings", I mean that the logs are saying "JNDI bindings for session bean... are as follows".
So maybe I'll have to throw away the optional="true"
plan.
Update #2
Since project A has a dependency on project B, project B is getting loaded by project A's classloader, which isn't a good thing in this case (right off the bat I'm seeing that the wrong log4j.xml file is being used).
Update #3
Using jboss-deployment-structure.xml to influence load order may not be enough. It looks like jboss-deployment-structure.xml can influence the order that classes load from the war's/ear's, but doesn't wait until their EJBs are started before starting to load the next deployment.
Any other ideas?
Thanks!