NATS云消息系统
nats 是一个轻量级的云消息系统,目前提供了使用 Go 开发的服务器版本以及多种编程语言的客户端开发包。 NATS是一个基于事件驱动的、基于发布和订阅模型的轻量级消息系统。它基于EventMachine实现。
吞吐量比较:
基本使用:
require "nats/client"
NATS.start do
# Simple Subscriber
NATS.subscribe('foo') { |msg| puts "Msg received : '#{msg}'" }
# Simple Publisher
NATS.publish('foo.bar.baz', 'Hello World!')
# Unsubscribing
sid = NATS.subscribe('bar') { |msg| puts "Msg received : '#{msg}'" }
NATS.unsubscribe(sid)
# Requests
NATS.request('help') { |response| puts "Got a response: '#{response}'" }
# Replies
NATS.subscribe('help') { |msg, reply| NATS.publish(reply, "I'll help!") }
# Stop using NATS.stop, exits EM loop if NATS.start started the loop
NATS.stop
end评论
