@@ -24,6 +24,12 @@ class LogStash::Inputs::Kafka < LogStash::Inputs::Base
24
24
# Specifies the ZooKeeper connection string in the form hostname:port where host and port are
25
25
# the host and port of a ZooKeeper server. You can also specify multiple hosts in the form
26
26
# hostname1:port1,hostname2:port2,hostname3:port3.
27
+ #
28
+ # The server may also have a ZooKeeper chroot path as part of it's ZooKeeper connection string
29
+ # which puts its data under some path in the global ZooKeeper namespace. If so the consumer
30
+ # should use the same chroot path in its connection string. For example to give a chroot path of
31
+ # /chroot/path you would give the connection string as
32
+ # hostname1:port1,hostname2:port2,hostname3:port3/chroot/path.
27
33
config :zk_connect , :validate => :string , :default => 'localhost:2181'
28
34
# A string that uniquely identifies the group of consumer processes to which this consumer
29
35
# belongs. By setting the same group id multiple processes indicate that they are all part of
@@ -34,6 +40,11 @@ class LogStash::Inputs::Kafka < LogStash::Inputs::Base
34
40
# Specify whether to jump to beginning of the queue when there is no initial offset in
35
41
# ZooKeeper, or if an offset is out of range. If this is false, messages are consumed
36
42
# from the latest offset
43
+ #
44
+ # If reset_beginning is true, the consumer will check ZooKeeper to see if any other group members
45
+ # are present and active. If not, the consumer deletes any offset information in the ZooKeeper
46
+ # and starts at the smallest offset. If other group members are present reset_beginning will not
47
+ # work and the consumer threads will rejoin the consumer group.
37
48
config :reset_beginning , :validate => :boolean , :default => false
38
49
# Number of threads to read from the partitions. Ideally you should have as many threads as the
39
50
# number of partitions for a perfect balance. More threads than partitions means that some
@@ -69,7 +80,7 @@ class LogStash::Inputs::Kafka < LogStash::Inputs::Base
69
80
70
81
public
71
82
def register
72
- jarpath = File . join ( File . dirname ( __FILE__ ) , " ../../../vendor/jar/kafka*/libs/*.jar" )
83
+ jarpath = File . join ( File . dirname ( __FILE__ ) , ' ../../../vendor/jar/kafka*/libs/*.jar' )
73
84
Dir [ jarpath ] . each do |jar |
74
85
require jar
75
86
end
@@ -86,7 +97,7 @@ def register
86
97
:consumer_id => @consumer_id ,
87
98
:fetch_message_max_bytes => @fetch_message_max_bytes
88
99
}
89
- if @reset_beginning == true
100
+ if @reset_beginning
90
101
options [ :reset_beginning ] = 'from-beginning'
91
102
end # if :reset_beginning
92
103
@kafka_client_queue = SizedQueue . new ( @queue_size )
@@ -107,7 +118,7 @@ def run(logstash_queue)
107
118
end
108
119
rescue LogStash ::ShutdownSignal
109
120
@logger . info ( 'Kafka got shutdown signal' )
110
- @consumer_group . shutdown ( )
121
+ @consumer_group . shutdown
111
122
end
112
123
until @kafka_client_queue . empty?
113
124
queue_event ( "#{ @kafka_client_queue . pop } " , logstash_queue )
@@ -117,7 +128,7 @@ def run(logstash_queue)
117
128
@logger . warn ( 'kafka client threw exception, restarting' ,
118
129
:exception => e )
119
130
if @consumer_group . running?
120
- @consumer_group . shutdown ( )
131
+ @consumer_group . shutdown
121
132
end
122
133
sleep ( Float ( @consumer_restart_sleep_ms ) * 1 / 1000 )
123
134
retry
@@ -131,13 +142,13 @@ def queue_event(msg, output_queue)
131
142
@codec . decode ( msg ) do |event |
132
143
decorate ( event )
133
144
if @decorate_events
134
- event [ 'kafka' ] = { ' msg_size' => msg . bytesize , ' topic' => @topic_id , ' consumer_group' => @group_id }
145
+ event [ 'kafka' ] = { : msg_size => msg . bytesize , : topic => @topic_id , : consumer_group => @group_id }
135
146
end
136
147
output_queue << event
137
148
end # @codec.decode
138
149
rescue => e # parse or event creation error
139
- @logger . error ( " Failed to create event" , :message => msg , :exception => e ,
140
- :backtrace => e . backtrace ) ;
150
+ @logger . error ( ' Failed to create event' , :message => msg , :exception => e ,
151
+ :backtrace => e . backtrace )
141
152
end # begin
142
153
end # def queue_event
143
154
0 commit comments