0

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?

cLar
  • 280
  • 1
  • 3
  • 17
  • Did you look at Web Services? – zenbeni Apr 02 '14 at 11:23
  • Using a message queue would provide a more resilient design and also allow for load-balancing – Nick Holt Apr 02 '14 at 11:23
  • @zenbeni web-services are typically running over http, which is inherently request/response, so the requirement to do push notifications is going to be difficult – Nick Holt Apr 02 '14 at 11:25
  • Are you looking for real-time sync of data? Your server that fetches data from different sources, does it fetch it periodically or is already listening to events? Do you want to fetch data per demand from other server or periodically even if nobody is listening for notifications? – zenbeni Apr 02 '14 at 11:29
  • My server will be listening to events (even if nobody is listening) and has to publish real time data, so pushing is absolutely necessary. – cLar Apr 02 '14 at 11:37
  • Are you limited to a Java only server for publishing (pushing) updates? Or can you add a broker (activemq) or a database (redis)? – zenbeni Apr 02 '14 at 11:47
  • Not sure right now, but a database might be OK, but I'm pretty sure everything else is not an option – cLar Apr 02 '14 at 11:51

3 Answers3

1

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.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • I was hoping that there are frameworks capable of what i want to achieve. Does xSocket work with non-java "clients", e.g. running on a .NET platform? – cLar Apr 02 '14 at 11:39
  • Yes you can certainly connect from .net or as a matter of fact from any other partner that has TCP connection capability (I guess all languages where you can do lower-level stuff and also applets, Flash clients etc., but not plain browser). Then you can send XML, JSON or custom string commands formatted as you please. – Kristjan Veskimäe Apr 03 '14 at 08:26
  • I chose this answer over the others as sockets are truly independent of the client platform and don't need any additional software. Thanks for all your answers! – cLar Apr 07 '14 at 14:15
1

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.

Nick Holt
  • 33,455
  • 4
  • 52
  • 58
1

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.

zenbeni
  • 7,019
  • 3
  • 29
  • 60