What is RMI via JMS?
RMI via JMS is a small java library that allows you to do Java Remote Method Invocations (RMI) via a Java Message Service (JMS) provider like ActiveMQ .
Why do that? If you like the simplicity of the RMI programing model, but hate the short comings of JRMP (the default socket based protocol used by RMI). Lets compare RMI via JMS and JRMP.
Firewall Configuration Complexity
| Standard RMI | Large RMI deployments present a Firewall management nightmare. RMI clients have to be able to TCP connect to dynamic network ports on the hosts exposing objects for remote invocation. When using client callbacks, severs need to be able to connect to the dynamic network ports on the client. |
|---|---|
| RMI via JMS | When used with ActiveMQ, RMI clients and servers (even when using client callbacks) just need to be able to connect to 1 well known port on the JMS server. Could be more complex based on JMS provider, but most providers do support the simple centralized server deployment. |
Network Robustness
| Standard RMI | TCP based, so network errors are quickly reported to the client. Does not load balance over many nodes and cannot fail over requests to other nodes. |
|---|---|
| RMI via JMS | Network failures are handled by the JMS provider. Requests can load balance across multiple nodes. Requests from a failed node can be processed by another node. |
Getting Started
If you have an existing RMI application, to switch it to use RMI via JMS you need to search for where you have used `java.rmi.server.UnicastRemoteObject` and replace it with `org.fusesource.rmiviajms.JMSRemoteObject`.
For example, if you had the following server object:
public class HelloWorldCallback
extends UnicastRemoteObject
implements IHelloWorldCallback {
HelloWorldCallback() throws RemoteException {
}
public void execute(String value) {
System.out.println("Hello World: "+value);
}
}
public class HelloWorldCallback
extends JMSRemoteObject
implements IHelloWorldCallback {
HelloWorldCallback() throws RemoteException {
}
public void execute(String value) {
System.out.println("Hello World: "+value);
}
}
See the User Guide For more examples.