Created
February 1, 2011 02:18
-
-
Save ezmobius/805292 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module('NATS', package.seeall) | |
require('list') | |
require ("datadumper") | |
NATS = {} | |
NATS.client = require('socket').tcp() | |
NATS.url = require('socket.url') | |
NATS.pending = {} | |
local CR_LF = "\r\n" | |
function NATS.new(uri) | |
NATS.conn = NATS.url.parse(uri) | |
NATS.client:connect(NATS.conn.host, NATS.conn.port) | |
end | |
function NATS.send_command(text) | |
NATS.client:send(text) | |
local res = NATS.client:receive('*l') | |
return res | |
end | |
function NATS.publish(subject, msg) | |
NATS.send_command("PUB " .. subject .. ' ' .. string.len(msg) .. CR_LF .. msg .. CR_LF) | |
end | |
NATS.new("nats://localhost:4222") | |
local subject = arg[1] | |
local msg = arg[2] | |
NATS.publish(subject, msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment