Messagebus =

A gem for publishing and consuming hornetq messagebus messages.

Installation ==

$ gem install mbus

Dependencies ==

This Gem depends upon the following:

Runtime ===

  • messagebus (vendored an old version for now)

  • thrift

  • json

Development & Tests ===

  • bundle install

  • Execute rspec spec

Configuration ==

The messagebus is configured via a single yaml file. The configuration fields are defined below and an example of a full configuration also provided.

  • enable_auto_init_connections: turn on producer connections once initialized

  • log_file: path for log

  • log_level: logger level minimum

  • logger: pass a logger directly to the messagebus client

  • worker_log_file: path for worker log

  • cluster_defaults

** user: hornetq user ** passwd: hornetq password ** receipt_wait_timeout_ms: TODO ** conn_lifetime_sec: TODO

  • clusters: array of haproxy clusters

** type: producer-cluster or consumer-cluster ** address: host and port of haproxy delimited by colon ** destinations: array of queue and topic destinations

  • swarm_config

** fork: true or false – whether to use forks or threads when booting drones

  • workers

** destination: the destination name ** worker: the worker class to process messages with ** subscription_id: swarm_drone_run_spec_id ** ack_on_error: whether to send an ack for a job that failed ** drones: number of drones to boot up for parallel processing

”‘Example config”’

enable_auto_init_connections: true 
log_file: log/messagebus-client.log
worker_log_file: log/messagebus-consumer.log

:swarm_config:
  # :fork: true

:workers:
  -
    :destination: jms.topic.testTopic2
    :worker: SimpleDroneRunSpecWorker
    :subscription_id: swarm_drone_run_spec_id

    :ack_on_error: false
    :drones: 1

:cluster_defaults:
  :user: guest
  :passwd: guest
  :receipt_wait_timeout_ms: 1500
  :conn_lifetime_sec: 300
  :enable_dynamic_serverlist_fetch: true  

clusters:
  -
    name: orders-messagebus-cluster
    producer_address: localhost:61613
    consumer_address: localhost:61613
    destinations:
      - jms.topic.testTopic2

Getting Started ==

You will find an example listed of loading a configuration, instantiation of a client, and finally invocation of the publish method. There are three different message types that can be published on the bus, string, binary, or json. An example of each are listed with concrete code to use.

In its current state, the messagebus gem should be vendored into your application. This will change once the internal rubygems server is integrated into the company. For now, unpack the gem and include “thrift” 0.9.0 into your Gemfile next to the messagebus declaration.

Edit Gemfile ===

gem "thrift", "0.9.0"
gem "messagebus", "x.x.x", :path => "vendor/gems/messagebus-x.x.x", :require => "messagebus"

Bundle your gems ===

$ bundle

Producing Messages ==

Run interactive ruby ===

$ irb

ruby>
require "messagebus" # Notice this will happen by default in the bundler

ruby>
binary_to_publish = "\xfe\x3e\x5e"
config = YAML.load_file("./config/messagebus.yml")
client = Messagebus::Client.new(config.merge(:logger => Logger.new("a/directory/to/my/file.log")))  
client.start
client.publish "jms.queue.testQueue1", binary_to_publish

ruby>
string_to_publish = "the quick brown fox jumped over the lazy dogs back"
config = YAML.load_file("./config/messagebus.yml")
client = Messagebus::Client.new(config.merge(:logger => Logger.new("a/directory/to/my/file.log")))  
client.publish "jms.queue.testQueue1", string_to_publish

ruby>
hash_to_publish = { :ruby => { :loves => :the_bus } }
config = YAML.load_file("./config/messagebus.yml")
client = Messagebus::Client.new(config.merge(:logger => Logger.new("a/directory/to/my/file.log")))  
client.publish "jms.queue.testQueue1", hash_to_publish

ruby>
object_to_publish = DomainObjectThatRespondsToToJson # object_to_publish.to_json will happen automatically
config = YAML.load_file("./config/messagebus.yml")
client = Messagebus::Client.new(config.merge(:logger => Logger.new("a/directory/to/my/file.log")))  
client.publish "jms.queue.testQueue1", object_to_publish

Watch Tail Processing Log ===

The tail will start displaying new log messages.

$ tail -f log/messagebus-client.log

Consuming messages ==

You have 2 options. Option 1 is write your own consumer class. See [[github.com/groupon/Message-Bus/blob/master/mbus-ruby/examples/consumer_topic_example.rb|consumer_topic_example.rb]] for how to write your own consumer.

Your other option is to use the Message Swarm code. Try examples/swarm_example.sh. See [[github.com/groupon/Message-Bus/wiki/Swarm-Consumer|Swarm Guide]] for more on that.

More detail needed? ==

Contact us via email! [email protected]

If something is not behaving intuitively, it is a bug and should be reported. Report it here: github.groupon.com/data-infrastructure/ruby-messagebus

Note on Patches/Pull Requests ==

  • Fork the project.

  • Make your feature addition or bug fix.

  • Commit, do not mess with rakefile, version, or history.

  • Send me a pull request. Bonus points for topic branches.

Copyright ==

Copyright © 2011 Groupon. Released under the MIT License.

See LICENSE for details.