Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Proof of concept

  • Loading branch information...
commit 5acabbda6c0902bae489157ec767ff6f527c1b0e 0 parents
@rodjek authored
Showing with 57 additions and 0 deletions.
  1. +2 −0  lib/meld.rb
  2. +18 −0 lib/meld/consumer.rb
  3. +37 −0 lib/meld/event.rb
2  lib/meld.rb
@@ -0,0 +1,2 @@
+require 'meld/event'
+require 'meld/consumer'
18 lib/meld/consumer.rb
@@ -0,0 +1,18 @@
+require 'stomp'
+require 'json'
+
+module Meld
+ class Consumer
+ def self.run
+ queue = '/queue/meld-events'
+
+ client = Stomp::Client.new 'guest', 'guest', 'localhost', 61613, true
+ client.subscribe queue, { :ack => :client } do |message|
+ data = JSON.parse(message.body)
+ Meld::Event.create(data)
+ client.acknowledge message
+ end
+ client.join
+ end
+ end
+end
37 lib/meld/event.rb
@@ -0,0 +1,37 @@
+require 'mongo'
+require 'stomp'
+require 'json'
+
+module Meld
+ class Event
+ def self.db
+ @db ||= Mongo::Connection.new.db('meld')
+ @coll ||= @db.collection('events')
+ end
+
+ def self.create(object)
+ time = object['created_at'] || Time.now.utc
+ db.save(object.merge('created_at' => time))
+ end
+
+ def self.find(conditions = {}, options = {})
+ default_conditions = {
+ # probably going to want to default to just showing the last
+ # 24 hours here
+ }
+ default_options = {
+ :sort => [['created_at', 'descending']],
+ }
+
+ db.find(default_conditions.merge(conditions),
+ default_options.merge(options)).to_a
+ end
+
+ def self.emit(object)
+ data = object.respond_to?(:to_json) ? object.to_json : object.to_s
+ client = Stomp::Client.new 'guest', 'guest', 'localhost', 61613, true
+ client.send('/queue/meld-events', data, {:persistent => true})
+ client.close
+ end
+ end
+end

0 comments on commit 5acabbd

Please sign in to comment.
Something went wrong with that request. Please try again.