Skip to content

computePods/luv-nats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Lua-Luv-NATS library

A Lua-Luv client for the NATS messaging system.

This is a fork of the original Lua-Nats project by dawnangel taken on April 23 2021 (commit 980da7a on 6 Jul 2018).

The original Lua-Nats client uses an essentially asynchronous style of programming. It made the simplifying assumption that the asynchronous "loop" could be a blocking call on the read function of the network socket connected to the NATS server. Unfortunately, this assumption means that the original Lua-Nats module can not easily inter-operate with any other asynchronous system. This Luv-Nats fork, uses the Luv "loop" which in turn allows a greater range of aynschronous activities to be happen in parallel to the NATS messaging. This fork simply replaces the Lua-Nats' blocking read with Luv's asynchronous socket IO.

License

Requirements

Lua libraries:

External software:

This is a NATS Lua library for Lua 5.1, 5.2, 5.3 and 5.4. The libraries are copyright by their authors (see the LICENSE file for details), and released under the MIT license (the same license as Lua itself). There is no warranty.

Usage

Basic usage: Subscribe / Unsubscribe

local nats = require 'nats'

local client = nats.connect({
    host = '127.0.0.1',
    port = 4222,
})

-- connect to the server
client:connect()

-- callback function for subscriptions
local function subscribe_callback(payload)
    print('Received data: ' .. payload)
end

-- subscribe to a subject
local subscribe_id = client:subscribe('foo', subscribe_callback)

-- wait until 2 messages come
client:wait(2)

-- unsubscribe from the subject
client:unsubscribe(subscribe_id)

Basic usage: Publish

local nats = require 'nats'

local client = nats.connect({
    host = '127.0.0.1',
    port = 4222,
})

-- connect to the server
client:connect()

-- publish to a subject
local subscribe_id = client:publish('foo', 'message to be published')

Basic usage: User authentication

local nats = require 'nats'

local client = nats.connect({
    host = '127.0.0.1',
    port = 4222,
})

-- user authentication
local user, password = 'user', 'password'
client:set_auth(user, password)

-- connect to the server
client:connect()

Developer's Information

Installation of the libraries

To install the required libraries you can execute make deps.

Tests

Tests are in the tests folder. To run them, you require:

  • luarocks and telescope installed.
  • execute make test.

Creators

Original creator (2015):

Eric Pinto

This fork (2021):

Stephen Gaito

Bug reports and code contributions

These libraries are written and maintained by their users. Please make bug report and suggestions on GitHub (see URL at top of file). Pull requests are especially appreciated.

About

A Lua-Luv client for the NATS messaging system.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages