I have two Java 8 web applications deployed in Tomcat 7 that need to communicate. Application A has multiple instances (multiple Tomcat workers, A1... An
) that are load-balanced, and application B has a single instance. A can currently initiate communication with B via a SOAP web service exposed by B, over HTTP via localhost.
B now needs to initiate communication with all instances of A. Because A is load-balanced, B cannot use HTTP because A1... An
are all accessed via the same URL and B cannot control which instance will receive its request.
The ideal solution might be similar to a web socket connection - each instance of A would establish a persistent connection to B and B would push data to each 'subscriber'.
Given that
- both A and B are Java 8 applications
- both are deployed within the same Tomcat installation, and
- there is no requirement for non-Java applications to communicate with B
is there a strategy that satisfies this requirement?
I know that RMI is available but I don't know if it supports my requirements. In RMI would B need prior knowledge of each instance of A, and a way to uniquely identify them? Could a duplex connection be established by each instance of A to avoid B requiring any knowledge of A?
The answer is yes, RMI can meet this requirement. Each instance of application A can register a callback object with application B. Application B can iterate over all registered callback objects and notify in turn.