class LogStash::Inputs::Stomp

Public Instance Methods

register() click to toggle source
# File lib/logstash/inputs/stomp.rb, line 48
def register
  require "onstomp"
  @client = OnStomp::Client.new("stomp://#{@host}:#{@port}", :login => @user, :passcode => @password.value)
  @client.host = @vhost if @vhost
  @stomp_url = "stomp://#{@user}:#{@password}@#{@host}:#{@port}/#{@destination}"

  # Handle disconnects
  @client.on_connection_closed {
    connect
    subscription_handler # is required for re-subscribing to the destination
  }
  connect
end
run(output_queue) click to toggle source
# File lib/logstash/inputs/stomp.rb, line 80
def run(output_queue)
  @output_queue = output_queue 
  subscription_handler
end

Private Instance Methods

connect() click to toggle source
# File lib/logstash/inputs/stomp.rb, line 36
def connect
  begin
    @client.connect
    @logger.debug("Connected to stomp server") if @client.connected?
  rescue => e
    @logger.debug("Failed to connect to stomp server, will retry", :exception => e, :backtrace => e.backtrace)
    sleep 2
    retry
  end
end
subscription_handler() click to toggle source
# File lib/logstash/inputs/stomp.rb, line 63
def subscription_handler
  @client.subscribe(@destination) do |msg|
    @codec.decode(msg.body) do |event|
      decorate(event)
      @output_queue << event
    end
  end
  #In the event that there is only Stomp input plugin instances
  #the process ends prematurely. The above code runs, and return
  #the flow control to the 'run' method below. After that, the
  #method "run_input" from agent.rb marks 'done' as 'true' and calls
  #'finish' over the Stomp plugin instance.
  #'Sleeping' the plugin leves the instance alive.
  sleep
end