Ruby gem for subscribing, unsubscribing and sending events to the Magic Broker 2.
This gem is already published on rubygems.org, so you can actually just include it in your application.
If you're writting a Rails application, first add the following line to your Gemfile file:
gem 'magicbroker', '0.2.1'
Then you can include it in any controller like so:
require 'magicbroker'
If you want to download the latest version of the gem, fork this repository and you can find the packaged gem in the /pkg directory.
For ease you can declare a global broker entity, in /apps/controllers/application_controller.rb:
require 'magicbroker'
def magicbroker
@magicbroker = Magicbroker::Client.new("localhost:8800/osgibroker", "clientID", "topic")
end
Then you can use your global object. For example, sending events:
magicbroker.subscribe()
hash = {:key1 => "value1", :key2 => "value2", :key3 => "value3"}
magicbroker.send_events(hash)
Unsubscribing:
magicbroker.unsubscribe()
Querying events (default timeout of 1 second). You can delegate this task to a Resque worker running in the background:
magicbroker.receive_events(nil)
You can initialize a new magicbroker object, subscribe, receive events and send a key/value pair event:
require 'magicbroker'
myentity = Magicbroker::Client.new("localhost:8800/osgibroker", "clientID", "topic")
myentity.subscribe()
myentity.receive_events(20) #define a timeout of 20 seconds
myhash = {:key => "value"}
myentity.send_events(myhash)
This gem was built using 'echoe', to install the gem in your system run:
rake manifest #To first test the file.
rake install #To install in your system.
ATTENTION: this is only for developers. You can publish the gem to rubygems.org by running the task:
rake release
or to be more specific:
gem push pkg/magicbroker-<version>.gem