Skip to content

NetComposer/nkservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NkSERVICE

Introduction

NkSERVICE is an Erlang framework to manage a complex set of services in a cluster. It features:

  • A powerful plugin mechanism, so that any service is made of a set of plugins and a bit of custom login.
  • New plugins can be added or removed at any moment. Its configuration can be changed at any moment.
  • A flexible and easy to use External API, that any service can expose over tcp, tls, ws or wss. Each started plugins in the service can add commands, making them available for use from outside the cluster.
  • A powerful events mechanism with publish/subscribe semantics.
  • A way to define service configuration and to develop server-side code using Luerl, a Lua-like language that is translated to Erlang on the fly.
  • Designed from scratch to be highly scalable, having a very low latency.

The vision around NkSERVICE is using Erlang to develop plugins that are offered to services. Service specific login can run inside the cluster (using Luerl or Erlang) or out of the cluster using the External API.

Plugins

NkSERVICE features a sophisticated plugin system, that allows a developer to modify the behavior of services without having to modify its core, while having nearly zero overhead. Each plugin adds new APIs and callbacks or hooks, available to the service developer or other, higher level plugins.

Plugins have the concept hierarchy and dependency. For example, if pluginA implements callback callback1, we can define a new plugin pluginB which depends on pluginA and also implements callback1. Now, if the service (or other higher level plugin) happens to use this callback1, when it is called by NkSERVICE, the one that will be called first will ve the pluginB version, and only if it returns continue or {continue, Updated} the version of pluginA would be called.

Any plugin can have any number of dependent plugins. NkSERVICE will ensure that versions of plugin callbacks on higher order plugins are called first, calling the next only in case it passes the call to the next plugin, possibly modifying the request. Eventually, the call will reach the default NkSERVICE's implementation of the callback (defined in nkservice_callbacks.erl if all defined callbacks decide to continue, or no plugin has implemented this callback).

Plugin callbacks must be implemented in a module with the same name of the plugin, or a module called with the same name as the plugin plus _"callbacks" (for example my_plugin_callbacks.erl).

This callback chain behavior is implemented in Erlang and compiled on the fly, into a run-time generated service callback module. This way, any call to any plugin callback function is blazing fast, exactly the same as if it were hard-coded from the beginning. Calls to plugin callbacks not implemented in any plugin go directly to the default NkSERVICE implementation.

Each service can have different set of plugins, and it can it be changed in real time as any other service configuration value.

Services

New services can be defined in NkSERVICE's global configuration, or programatically using Erlang or the external API. Also, any file with extension .ncl in the directory services will be loaded during boot, and, if they contain valid service definitions (written in Luerl), will be started.

Services can also be started using the External API, but you must authenticate yourself using the user and password defined in NkSERVICE's global configuration. You can this way inject the Luerl service definition and logic, or subscribe to all the callback functions you are interested in implement.

When defining a service, you can set an administrator users and password. Special commands, like subscribing to callback functions, can only be performed by the administrator of the service.

External API

NkSERVICE offers a flexible, easy to use protocol suitable for developing both client-side applications (supporting hundreds of thousands of connections) and server-side applications, where an external application written in any language can start any number of channels to a service, and receive incoming tasks and messages, that are load-balanced over all started channels.

See the external API introduction for a description of the protocol, and external API commands for currently implemented commands and events in NkSERVICE. Any activated plugin for a service can add new commands and events, of modify the behavior of current ones.

Packages

No packages published

Languages