This file contains 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
Create uninstantiated class from a string | |
========================================= | |
Object::const_get('String') | |
Create instantiated class from a string | |
======================================= | |
Object::const_get('String').new |
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
# 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. | |
# |
This file contains 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
# 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 |
This file contains 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
require 'json' | |
def valid_json?(str) | |
begin | |
JSON.parse(str) | |
return true | |
rescue Exception => e | |
return false | |
end | |
end |
This file contains 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
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 |
This file contains 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
# /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}]}, |
This file contains 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
q = b.queue('testq', :arguments => {"x-expires" => 120000}) # idle queue expires after 2 mins |
This file contains 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
q.publish('test message', :expiration => "60000") # message will reside in queue maximum 1 minute |
OlderNewer