You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
localnats=require'nats'-- connect to the serverlocalclient=nats.connect({
host='127.0.0.1',
port=4222,
})
-- callback function for subscriptionslocalfunctionsubscribe_callback(payload)
print('Received data: ' ..payload)
end-- subscribe to a subjectlocalsubscribe_id=client:subscribe('foo', subscribe_callback)
-- wait until 2 messages comeclient:wait(2)
-- unsubscribe from the subjectclient:unsubscribe(subscribe_id)
Basic usage: Publish
localnats=require'nats'-- connect to the serverlocalclient=nats.connect({
host='127.0.0.1',
port=4222,
})
-- publish to a subjectlocalsubscribe_id=client:publish('foo', 'message to be published')
Basic usage: User authentication
localnats=require'nats'localclient=nats.connect({
host='127.0.0.1',
port=4222,
})
-- user authenticationlocaluser, password='user', 'password'client:set_auth(user, password)
-- connect to the serverclient:connect()