Skip to content

Framework for building microservices with Lua

Notifications You must be signed in to change notification settings

somata/somata-lua

Repository files navigation

Somata for Lua

Somata is a framework for building networked microservices, supporting both remote procedure call (RPC) and publish-subscribe models of communication. This is the Lua version of the library, see also somata-node and somata-python.

Note: This implementation of the Somata Protocol is incomplete - it supports remote method calls but not event subscriptions.

Installation

Install with the LuaRocks package manager:

$ luarocks install somata

Getting started

First make sure the Registry is installed and running:

$ somata-registry
[Registry] Bound to 127.0.0.1:8420

Creating a Service

Create a Service using somata.Service.create(name, methods). The methods argument is a table of named functions; every function is asynchronous and takes a callback as its last argument.

This example (see examples/hello-service.lua) creates a Service named "hello" with a single method sayHello(name, cb):

local somata = require 'somata'

local service = somata.Service.create('hello', {
    sayHello = function(name, cb) cb(nil, "Hello, " .. name .. "!") end,
})

Creating a Client

Create a Client using somata.Client.create().

Call a remote method of a Service using client.remote(service, method, args, cb). The callback function takes two argments, err and response.

This example (see examples/hello-client.lua) connects to the "hello" service, and calls the sayHello method:

local somata = require 'somata'

local client = somata.Client.create()

client:remote("hello", "sayHello", {"world"}, function(err, response)
    print('Got response:', response)
end)

client.loop:start()

About

Framework for building microservices with Lua

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages