Skip to content

Instantly share code, notes, and snippets.

@rasputnik
Created March 14, 2013 10:52
Show Gist options
  • Save rasputnik/5160442 to your computer and use it in GitHub Desktop.
Save rasputnik/5160442 to your computer and use it in GitHub Desktop.
# run with "jruby --1.9 /path/to/this.rb" and wait 10 minutes
class Thing
def initialize
require 'cabin'
@logger = Cabin::Channel.new
sout = Logger.new(STDOUT)
@logger.level = :debug
@logger.subscribe(sout)
end
def register
require "bunny"
@logger.debug("Registering output", :plugin => self)
setupconf
connect
end # def register
def setupconf
@vhost = "/logstash"
@host = "amqp.org.uk"
@user = "logger"
@password = "pass"
@exchange = "logstash"
@exchange_type = "topic"
@port = 5672
@debug = false
@ssl = false
@verify_ssl = false
@persistent = true
@durable = true
@frame_max = 131072
@key = "logs.broken"
end
public
def connect
rabbitmq_settings = {
:vhost => @vhost,
:host => @host,
:port => @port,
:logging => @debug,
}
rabbitmq_settings[:user] = @user if @user
rabbitmq_settings[:pass] = @password if @password
rabbitmq_settings[:ssl] = @ssl if @ssl
rabbitmq_settings[:verify_ssl] = @verify_ssl if @verify_ssl
rabbitmq_settings[:frame_max] = @frame_max if @frame_max
@logger.debug("Connecting to RabbitMQ", :settings => rabbitmq_settings,
:exchange_type => @exchange_type, :name => @exchange)
@bunny = Bunny.new(rabbitmq_settings)
@bunny.start
@logger.debug("Declaring exchange", :name => @exchange, :type => @exchange_type,
:durable => @durable)
@bunnyexchange = @bunny.exchange(@exchange, :type => @exchange_type.to_sym, :durable => @durable)
@logger.debug("Binding exchange", :name => @exchange, :key => @key)
end # def connect
public
def to_s
return "amqp://#{@user}@#{@host}:#{@port}#{@vhost}/#{@exchange_type}/#{@exchange}\##{@key}"
end
public
def teardown
@bunny.close rescue nil
@bunny = nil
@bunnyexchange = nil
finished
end # def teardown
end
t = Thing.new
t.register
sec = 0
loop do
sleep(15)
sec += 15
puts sec
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment