View class_creation.rb
Create uninstantiated class from a string
=========================================
Object::const_get('String')
Create instantiated class from a string
=======================================
Object::const_get('String').new
View heart_monitor.rb
require 'bunny' # Change this to point to the test version of bunny.rb otherwise you will probably be asking for the gem
require 'timeout'
b = Bunny.new(:logging => true, :heartbeat => 30) # Set heartbeat to 30 seconds
# Create a new heartbeat frame
hb = Qrack::Transport::Heartbeat.new()
b.start
View simple_heartbeat.rb
require 'bunny'
b = Bunny.new(:logging => true, :heartbeat => 15)
b.start
q = b.queue('hb_test')
Thread.new do
q.subscribe {|msg| puts msg[:payload]}
end
View Experimental Subscription
# This is how Queue#subscribe will work in the next version of Bunny (v0.5.4).
# It's in the 'experimental' branch now.
#
# In order for subscription to work smoothly you need to use a combination of
# Queue#subscribe, Queue#unsubscribe, Queue#ack and Client#qos prefetch. The
# prefetch will allow a controlled number of messages to be released to a
# consumer, which means that Queue#unsubscribe and other methods can be run
# without errors due to out of sequence messages.
#
View teepee.rb
# teepee.rb - For all of you camping users who can't find this elsewhere
#!/usr/bin/env ruby
$:.unshift File.dirname(__FILE__) + "/../../lib"
%w(rubygems camping camping/db redcloth acts_as_versioned).each { |lib| require lib }
Camping.goes :Tepee
module Tepee::Models
View gist:2313898
require 'json'
def valid_json?(str)
begin
JSON.parse(str)
return true
rescue Exception => e
return false
end
end
View bunny_connect.rb
require 'bunny'
# Usual arguments
conn = Bunny.new(:host => 'myhost', :ssl => true)
conn.start
puts conn.status # :open
puts conn.ssl? # true
# URI
conn2 = Bunny.new("amqps://myhost/%2F") # %2F is '/' URL encoded
View gist:4241084
# /etc/rabbitmq/rabbitmq.config
#
# Follow the instructions on RabbitMQ website to create certificate authority and certificates -
#
# http://www.rabbitmq.com/ssl.html
#
[
{rabbit, [
{tcp_listeners,[{"127.0.0.1",5672}]},
View gist:4247130
q = b.queue('testq', :arguments => {"x-expires" => 120000}) # idle queue expires after 2 mins
View gist:4247204
q.publish('test message', :expiration => "60000") # message will reside in queue maximum 1 minute