Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good Java-based Master-Slave communication mechanism?

Tags:

I'm creating a Java application that requires master-slave communication between JVMs, possibly residing on the same physical machine. There will be a "master" server running inside a Java EE application server (i.e. JBoss) that will have "slave" clients connect to it and dynamically register itself for communication (that is the master will not know the IP addresses/ports of the slaves so cannot be configured in advance). The master server acts as a controller that will dole work out to the slaves and the slaves will periodically respond with notifications, so there would be bi-directional communication.

I was originally thinking of RPC-based systems where each side would be a server, but it could get complicated, so I'd prefer a mechanism where there's an open socket and they talk back and forth.

I'm looking for a communication mechanism that would be low-latency where the messages would be mostly primitive types, so no serious serialization is necessary. Here's what I've looked at:

  • RMI
  • JMS: Built-in to Java, the "slave" clients would connect to the existing ConnectionFactory in the application server.
  • JAX-WS/RS: Both master and slave would be servers exposing an RPC interface for bi-directional communication.
  • JGroups/Hazelcast: Use shared distributed data structures to facilitate communication.
  • Memcached/MongoDB: Use these as "queues" to facilitate communication, though the clients would have to poll so there would be some latency.
  • Thrift: This does seem to keep a persistent connection, but not sure how to integrate/embed a Thrift server into JBoss
  • WebSocket/Raw Socket: This would work, but require a lot more custom code than I'd like.

Is there any technology I'm missing?

Edit: Also looked at:

  • JMX: Have the client connect to JBoss' JMX server and receive JMX notifications for bidirectional comms.
like image 639
Phuong LeCong Avatar asked Apr 07 '10 18:04

Phuong LeCong


People also ask

How do slaves and master communicate?

Master/slave is a model of asymmetric communication or control where one device or process (the "master") controls one or more other devices or processes (the "slaves") and serves as their communication hub.

Which communication allow master-slave communication?

I2C and SPI are the most popular communication buses used for simple master-slave communication in the current esigns. This article will explore I2C and SPI specification in detail.

What is master-slave approach?

A master-slave approach is presented where a mobile camera (the slave) can match any object detected by a fixed camera (the master). Features extracted by the master camera are used to detect the object of interest in the slave camera without the use of any training data.

Is client/server the same as master-slave?

Master Slave is a concept of one controller and one or many worker, whilst a server-client describes a relation between two things, e.g. used in network scenarios that says there is a central point that offers something (e.g. data, functionality, ...) and others that consume it (clients).


2 Answers

Well, I suggest JMS if you are looking for something which is based on Java. It has all the features that you are looking for plus a strong application server such as JBoss. However, another option which is not completely java based and is not using Queues would be using using HTTP protocol and JAXB (RESTful Web services). This is a very light way of communicating between two sides. Your objects would be transformed to XML by using JAXB, and would be transferred to the other side, and then you cast it back to object once you receive it.

like image 185
paradisonoir Avatar answered Sep 22 '22 05:09

paradisonoir


Honestly, I would just stick with JMS. You have one queue your slaves can take messages out of, and one queue that they put them back into. You can set properties about who processed each message (for accounting) right on the envelope. You get persistence with many J2EE providers (glassfish, jboss).

Plus, you can easily move to multiple-server distributed JVM with it with no extra programming.

However, it may not fit the definition of "low-latency" in some cases.

like image 21
Chris K Avatar answered Sep 25 '22 05:09

Chris K