cLar
cLar

Reputation: 280

Java server-to-server interface

I have to design a (java) interface for server-to-server communication, but I have no experience what so ever in this field.

My Server fetches information from different sources. Other servers shall be able to connect to the server and get the current information as well as receive changes via push notifications. The interface should not depend on certain programming languages or operating systems for those other servers. My first thought was to use sockets and leave the socket open to transmit changes. Is there a better way to this?

Upvotes: 0

Views: 450

Answers (3)

Kristjan Veskimäe
Kristjan Veskimäe

Reputation: 992

I guess working in a Java EE environment the easiest would be using web services. But if this is not the case and/or you need pushing, I would recommend using some library. For example xSocket that uses non-blocking IO sockets and can send and receive any string messages asynchronously. From there on you can use for example JAXB binders to send XML messages or any other format.

Upvotes: 1

zenbeni
zenbeni

Reputation: 7193

If you require good performance with real-time data, you can have a look at redis which is a nosql database all-in-memory that supports publish/subscribe and has many clients for all major languages.

Your publishing server will listen to events and push data into redis thanks to jedis (redis client for java) for instance, then thanks to the publish/subscribe support of redis, your other servers that subscribed to the redis channel will get updates. Basically you use redis as a message broker, and it works well. If you don't want to add intelligence on reads, redis is definitely a good choice.

You will however need to deploy it on a linux server (no windows for production, but you can use a windows port of redis for developping).

Redis adds complexity but also has many great features (zsets are wonderful for stocking rankings of data) and as it is all in memory (you will have to check if you have enough RAM though on your server), the performance is very great.

Upvotes: 1

Nick Holt
Nick Holt

Reputation: 34311

Due to your requirement to be able to push data to the client, while this is obviously possible with sockets, they do introduce other complexities and so, imho, the easiest solution would be to use a message queue.

To use a message queue, the client would post a message to a known queue that the server is listening to. This message should contain a replyTo destination (typically a temporary queue owned by the client). On receiving a message, the server should register the replyTo destination, sending any notifications to this replyTo destination.

I've normally found it easier to use the notification mechanism for all data - both the initial load and the updates - as it prevents the client from having to support two mechanisms to obtain data. This is very easy to do, as your notification messages will need to indicate what type of event is occurring (add, update, delete for example) and you just need to introduce an initialize type to this list.

Upvotes: 1

Related Questions