4

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!

Jon Onstott
  • 13,499
  • 16
  • 80
  • 133
  • 1
    snarky answer is this is what .ear files are for. but realistically, what do you mean one depends on the other? How are they bound together? – Tea Curran Sep 16 '15 at 03:40
  • Lol. Project A uses an EJB in Project B, from code that runs on startup. So if Project B isn't up and running, A errors out. We could build a retry mechanism, but would prefer not to since we have MANY projects that work this way. – Jon Onstott Sep 16 '15 at 15:43
  • hmm. have you thought about trying to use resource-ref in your web.xml to reference the jndi of your ejb? if that works it might be more flexible than the module dependency. I've never tried this though so I can't say for sure if it will work. – Tea Curran Sep 16 '15 at 17:47
  • @TerrenceCurran I'll check on that, thanks for the tip. If you have any other ideas I'd like to hear them too. – Jon Onstott Sep 16 '15 at 21:31
  • You should use a jboss-all.xml file, but `optional` is not supported unfortunately. Just as a reference: https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.1/html/Administration_and_Configuration_Guide/Control_the_order_of_Deployed_Applications_on_JBoss_Enterprise_Application_Platform.html – Linuslabo Jan 12 '17 at 12:07

0 Answers0