Skip to content

Instantly share code, notes, and snippets.

@ncrohn
Last active December 12, 2015 08:18
Show Gist options
  • Save ncrohn/4743223 to your computer and use it in GitHub Desktop.
Save ncrohn/4743223 to your computer and use it in GitHub Desktop.
Node.js real-time remote services
{
"name": "consumer-name",
"version": "1.0.0"
}

Node.js Real-time Remote Service Messaging System

Goal

To develop an architecture that provides a way for real-time communication between a dynamic set of remote services.

Services

A service is defined as a process that given some input the service will provide an output that can stand on it's own.

As a service comes online it connects to the system on a socket connection. The system will authorize the service and tell the service to complete registering. Registration will attach the required listeners as well as any custom listeners for specific features the service exposes. This will be done with a JSON configuration. This configuration allows the system to know what is available to other services on the system.

Services will be able to define a set list of methods that the service itself will provide. It is expected that services can be stand alone and do not require the system to operate.

Consumers

A consumer is defined as a process that is designed to interact with services on the system. A consumer is not required to stand on it's own and a consumer can also be a service.

Consumers will register the same way as a service; however will not trigger the system to broadcast it's availability. Configuration will also be identical, except there will be no methods provided.

Core System Events

  • Service Connect: A service has registered itself and is available to recieve messages. Will be fired every time a service instance connects.
  • Service Online: A service has come online and is ready for use. Will only fire the first time a service becomes available.
  • Service Disconnect: A service has disconnected and it's instance is no longer available. Will be fired every time a service instance disconnects.
  • Service Offline: A service has disconnected and there are not further service instances on the system. Will only fire when the last service instance disconnects.
  • Broadcast Message: A new general message has come on the system that will broadcast to all service instances.
  • Unhandled Message: A message has not been delivered and so services are notified.

Core Service Events

  • Registered: The service has completed regitering and is ready for use
  • Connect: The service has connected to the system, but has not registered yet
  • Disconnect: The service has disconnected from the system and is no longer available.
{
"type": "message",
"id": "<UUID>",
"destination": "<service-name:method>",
"consumer": "<consumer-name>",
"responder": "<callback>",
"payload": <payload>
}
{
"name": "service-name",
"version": "1.0.0",
"methods": [
"method-1",
"method-2",
"method-(n)"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment