简体   繁体   中英

Java web application calling different other Java applications (workers)

I am looking for a better logical solution of a situation where one core Java EE (Web) application will call/execute many other Java applications/workers (which can be core Java or J2EE(web) application (don't know what will be the best)) at a certain time.

Those other Java applications/workers will basically connect (individually) with different Data sources (can be from remote DB or REST or SOAP, etc...) and populate/update local DB at a certain period of time.

I was doing research on Java Quartz Scheduler recently. Do u have any good suggestion to me for this Enterprise level architecture?

Btw, I am using Spring 4, Java 7

Thank you as always for all good and professional ideas.

Sample diagram can be as follows: 在此处输入图片说明

Not sure to understand good, but you can look at a messaging mechanism. Typically, the WebApp will send a message that will be received by all the Workers.

Have a look a JMS which it designed for this kind of use, and integrates well with both JEE (it is a part of the JEE spec) and Spring.

You can connect your java application with others easy with spring's httpInvoker or rmiInvoker . More information here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/remoting.html

There are basically two parts to your question:

  1. How do I schedule jobs on a Java EE server?
  2. How do I invoke remote services from that scheduled job?

Job Scheduling

The trick with job scheduling in a Java EE environment is that you are typically running jobs in a cluster, or more than one server. Thus, only one of the nodes should be running that job at a time "on behalf of" the cluster, otherwise, you'll get multiple calls to those remote resources for the same thing.

There is a standard out there for this, JSR-237 , which covers Timers and WorkManagers. Each Java EE vendor has its own implementation. WebLogic has one , WebSphere has one , and JBoss has one (the JBoss one isn't compliant with the JSR, but it does the same thing).

If you are running one of the servers that only runs the web tier of the Java EE spec (ie, Tomcat or Geronimo), then Quartz is a good choice.

How to invoke remote services from timed jobs

Echoing @Alexandre Cartapanis' answer, probably what you'll want to do is create a JMS Topic in your Java EE server, and then when the job runs, post a message to the topic. The remote services (whatever Java EE servers) subscribe to this topic, and then you can run your queries.

The big advantage here is that if you ever need to add another service that needs to populate the local DB, all you have to do is have that server subscribe to the topic - no code changes needed. With JSch or remoting, you'll have to make a code change every time a new service comes online. You also have to make code changes if DNS addresses or IP addresses change, etc, where as the JMS way is just configuration on the server. There's a lot more that you can do with JMS, and the support is much better across the board.

Spring has adapters for Quartz and I think there's one out there for WorkManagers and Timers too.

You can make use of JSch - Java Secure Channel to trigger remote ssh calls which can start a JVM and run the Worker class.
Here are some examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM