Class: LogStash::Inputs::Beanstalk

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/inputs/beanstalk.rb

Instance Attribute Summary

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from Base

#receive, #tag

Constructor Details

#initialize(url, type, config = {}, &block) ⇒ Beanstalk

Returns a new instance of Beanstalk.



7
8
9
10
11
12
13
# File 'lib/logstash/inputs/beanstalk.rb', line 7

def initialize(url, type, config={}, &block)
  super

  if @url.path == "" or @url.path == "/"
    raise "must specify a tube for beanstalk output"
  end
end

Instance Method Details

#registerObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logstash/inputs/beanstalk.rb', line 16

def register
  tube = @url.path[1..-1] # Skip leading '/'
  port = @url.port || 11300
  @beanstalk = EMJack::Connection.new(:host => @url.host,
                                      :port => port,
                                      :tube => tube)
  @beanstalk.each_job do |job|
    begin
      event = LogStash::Event.from_json(job.body)
    rescue => e
      @logger.warn(["Trouble parsing beanstalk job",
                   {:error => e.message, :body => job.body,
                    :backtrace => e.backtrace}])
      @beanstalk.bury(job, 0)
    end

    receive(event)
    @beanstalk.delete(job)
  end # @beanstalk.each_job
end