Class: LogStash::Outputs::Nsq

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/nsq.rb

Instance Method Summary collapse

Instance Method Details

#closeObject

def receive



81
82
83
84
# File 'lib/logstash/outputs/nsq.rb', line 81

def close
  @logger.info('closing nsq producer')
  @producer.terminate
end

#receive(event) ⇒ Object

def register



72
73
74
75
76
77
78
79
# File 'lib/logstash/outputs/nsq.rb', line 72

def receive(event)
  return unless output?(event)
  if event == LogStash::SHUTDOWN
    finished
    return
  end
  @codec.encode(event)
end

#registerObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/logstash/outputs/nsq.rb', line 17

def register
  options = {
      :nsqlookupd => @nsqlookupd,
      :topic => @topic,
      :tls_v1 => @tls_v1
  }
  # overwrite nsqlookupd options if client certificate validation is used:
  # this is very dirty. please fix 
  if @tls_key and @tls_cert
    options = {
        :nsqlookupd => @nsqlookupd,
        :topic => @topic,
        :tls_v1 => @tls_v1,
        :tls_context => {
         key: @tls_key,
         certificate: @tls_cert
        }
    }
  end
  # overwrite options if no nsqlookupd is used:
  if nsqlookupd == []
    if @tls_key and @tls_cert
      options = {
          :nsqd => @nsqd,
          :topic => @topic,
          :tls_v1 => @tls_v1,
          :tls_context => {
           key: @tls_key,
           certificate: @tls_cert
          }
      }
    else
      options = {
          :nsqd => @nsqd,
          :topic => @topic,
          :tls_v1 => @tls_v1
      }
    end
  end # if
  @producer = Nsq::Producer.new(options)
  #@producer.connect
  @logger.info('Registering nsq producer', :nsqd => @nsqd, :nsqlookupd => @nsqlookupd, :topic => @topic)

  @codec.on_event do |event, data|
    begin
      @producer.write(event.sprintf(data))
    rescue LogStash::ShutdownSignal
      @logger.info('nsq producer got shutdown signal')
    rescue => e
      @logger.warn('nsq producer threw exception, restarting',
                   :exception => e)
    end # begin
  end #do
end