Search code examples
javajmsprotocolsrpcthrift

Known RPC Protocols to put ontop of JMS


I am developing a distributed system which consists of different components (services) which are loosely (asynchronously) coupled via JMS (ActiveMQ).

Thus I do not want to reinvent the wheel, I am looking for a (well) known protocol / library that facilitates remote procedure calls inbetween these components and helps me deal with method interfaces.

So let's decompose the problem I am already solving right now via dirty solutions:

  1. A consumer component want's to call a service, thus it constructs a request string (hand-written and dirty)
  2. The request string is than compressed an put into a JMS message (dirty aswell)
  3. The request message is than transmitted via JMS and routing mechanisms (that part is ok)
  4. The service first of all needs to decompress and parse the request string, to identify the right method (dirty)
  5. The method gets called and the reply goes like #2 - #4.

So that looks pretty much like SOAP, whilst I think that SOAP is to heavy for my application and further I am not using HTTP at all. Given that I was thinking that one might be able to deconstruct the problem into different components.

  1. Part A: HTTP is replaced by JMS (that one is okay)
  2. Part B: XML is replaced by something more lightweight (alright, MessagePack comes in handy here)
  3. Part C: Mechanism to parse request/reply string to identify operation name and parameter values (that one is the real problem here)

I was looking into MessagePack, ProtocolBuffers, Thrift and so forth, but what I don't like about them is that they introduce their own way of handling the actual (TCP) communication. And bypass my already sophisticated JMS infrastructure (which also handles load balancing and stuff).

To further elaborate Part C above, this is how I am currently handling it: Right know I would do something like the following if a consumer would call a service, let's assume the service takes a text and replies keywords. I would have the consumer create a JMS message and transmit it (via ActiveMQ) to the service. The message would contain:

 Syntax: OPERATION_NAME [PARAMETERS]
 Method: GET_ALL_KEYWORDS [String text] returns [JSON String[] keywords]

 Example Request: GET_ALL_KEYWORDS "Hello world, this is my input text..."
 Example Reply: ["hello", "world", "text"]

Needless to say that it feels like hacked-together. The problem I see is if I would be to change the method interface by adding or deleting parameters, I would have to check all the request/reply string construction/deconstructions to syncronize the changes. That is pretty errorprone. I'd rather have the library construct the right request/reply syntax by looking at a java interface and throwing real exceptions on runtime if I do mess up stuff, like "Protocol Exception: Mandatory parameter not set" or something...

Any projects/libs known for that?

Requirements would be

  1. It's small and lightweight and fast.
  2. It's implemented in JAVA
  3. It doesn't serve too many purposes (like some fullblown framework e.g. Spring)

Solution

  • I think this Spring package is what you're looking for. See JmsInvokerProxyFactoryBean and related classes.

    From the javadoc:

    FactoryBean for JMS invoker proxies. Exposes the proxied service for use as a bean reference, using the specified service interface.

    Serializes remote invocation objects and deserializes remote invocation result objects. Uses Java serialization just like RMI, but with the JMS provider as communication infrastructure.