Created
February 4, 2012 20:11
-
-
Save mbj/1739829 to your computer and use it in GitHub Desktop.
simple evenstorm client interface
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
# 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