Skip to content

Instantly share code, notes, and snippets.

@mbj
Created February 4, 2012 20:11
Show Gist options
  • Save mbj/1739829 to your computer and use it in GitHub Desktop.
Save mbj/1739829 to your computer and use it in GitHub Desktop.
simple evenstorm client interface
# Simple evenstorm client library from brain
# Wo any testing, ZMQ API consultation etc
class Evenstorm
def initialize(connect_str)
@context = ZMQ::Context.new
@socket = @context.socket(::ZMQ::PUB)
@socket.connect(connect_str)
@socket.setsockopt(ZMQ::Linger,0)
at_exit do
@socket.close
@context.close
end
end
def fire(event)
bson = BSON.serialize(event.to_hash)
@socket.send(bson)
self
end
def self.setup(connect_string)
if defined?(@instance)
raise
end
@instance = self.new(connect_string)
end
def self.fire(event)
instance.fire(event)
end
def self.instance
@instnace || raise
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment