jruby-kafka 2.1-java → 2.2.2-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 583ea35b720a5b6300f4baf5e368cc499115051e
4
- data.tar.gz: e163c0f3b84a6134a2ceb269cc98c93cad6845f7
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2NjNzliNzVlOGViODcyZTEyN2UwNTA2MTg5ZWI5OTM3NDZjNDYwNA==
5
+ data.tar.gz: !binary |-
6
+ ODY0Y2MyNTQyN2QzMjg4N2M3MTVmZDZkNTMzYjA2YTE0NDk0MjYwNQ==
5
7
  SHA512:
6
- metadata.gz: 646ce387223e4cba598b8bdfa1a95873e25b438b5ea59837ef710e0520e0828e5b3affd84421e9eebac733cf14e7cc3baa05b8fcbebc5b66a562e902b505ec78
7
- data.tar.gz: 23e7d76a2baa94066a2daea8ac33fa609932f62e05f5a8f889e04e21df52398d58ba84789b08c8a9b7aeb77cb9947a43553cf84972a955ef06e85be01caf63f2
8
+ metadata.gz: !binary |-
9
+ MDU2OGU4YzRkNjRjNzg4ZTllNGZiM2YzZmM3NTA5NmFhYmU1NTMxYzEyM2Yx
10
+ MjdlNjM2NWIwMzRkYjE5ZWNmNDJkMWQ2OWYxYmY3ZTIyOGYzMGFjNTUzNWFl
11
+ ODg0YWZkNjdjNjI0ZTFlN2Q2OTdkNzY0NzkwOTg5MmRjNDRkMWU=
12
+ data.tar.gz: !binary |-
13
+ MzgwNDgzMWNhYWZkNGI5YjFlNmVhYjkxZjczNzQ3MjM3NTUyNTAwZjQ5OThi
14
+ YjUxYzk3MjVjOGQyMTYyNDUwNDgwNGI0YzhkNzg0ZGMxOTAyYjUxMjU4YWFk
15
+ ZmIyNmFmMmQ0OTllY2I0NGIwMWRlMGI1NDIwY2NjMzU0M2FmMDg=
@@ -1,8 +1,14 @@
1
1
  require 'java'
2
2
  require 'jruby-kafka/namespace'
3
+ require 'jruby-kafka/utility'
3
4
 
4
5
  class Kafka::Consumer
5
6
  java_import 'org.I0Itec.zkclient.exception.ZkException'
7
+ java_import 'kafka.consumer.ConsumerConfig'
8
+ java_import 'kafka.consumer.Consumer'
9
+ java_import 'kafka.consumer.Whitelist'
10
+ java_import 'kafka.consumer.Blacklist'
11
+ java_import 'kafka.utils.ZkUtils'
6
12
  # Create a Kafka high-level consumer.
7
13
  #
8
14
  # @param [Hash] config the consumer configuration.
@@ -40,8 +46,14 @@ class Kafka::Consumer
40
46
  @key_decoder = @properties.delete(:key_decoder) || 'kafka.serializer.DefaultDecoder'
41
47
  @msg_decoder = @properties.delete(:msg_decoder) || 'kafka.serializer.DefaultDecoder'
42
48
  @reset_beginning = @properties.delete :reset_beginning
49
+ @consumer = nil
50
+ end
43
51
 
44
- @consumer = Java::KafkaConsumer::Consumer.createJavaConsumerConnector create_config
52
+ # Create connection to Kafka and Zookeeper.
53
+ #
54
+ # @return void
55
+ def connect
56
+ @consumer = Consumer.createJavaConsumerConnector ConsumerConfig.new Kafka::Utility.java_properties @properties
45
57
  end
46
58
 
47
59
  # Start fetching messages.
@@ -54,9 +66,10 @@ class Kafka::Consumer
54
66
  #
55
67
  # @note KafkaStreams instances are not thread-safe.
56
68
  def message_streams
69
+ connect if @consumer.nil?
57
70
  begin
58
71
  if @reset_beginning == 'from-beginning'
59
- Java::kafka::utils::ZkUtils.maybeDeletePath(@properties[:zookeeper_connect], "/consumers/#{@properties[:group_id]}")
72
+ ZkUtils.maybeDeletePath(@properties[:zookeeper_connect], "/consumers/#{@properties[:group_id]}")
60
73
  end
61
74
  rescue ZkException => e
62
75
  raise KafkaError.new(e), "Got ZkException: #{e}"
@@ -74,8 +87,8 @@ class Kafka::Consumer
74
87
 
75
88
  else
76
89
  filter = @include_topics ?
77
- Java::KafkaConsumer::Whitelist.new(@include_topics) :
78
- Java::KafkaConsumer::Blacklist.new(@exclude_topics)
90
+ Whitelist.new(@include_topics) :
91
+ Blacklist.new(@exclude_topics)
79
92
 
80
93
  @consumer.
81
94
  createMessageStreamsByFilter(filter, @num_streams, key_decoder_i, msg_decoder_i).
@@ -98,11 +111,11 @@ class Kafka::Consumer
98
111
  # @return void
99
112
  def shutdown
100
113
  @consumer.shutdown if @consumer
114
+ @consumer = nil
101
115
  nil
102
116
  end
103
117
 
104
118
  private
105
-
106
119
  def validate_arguments(options)
107
120
  [:zookeeper_connect, :group_id].each do |opt|
108
121
  raise ArgumentError, "Parameter :#{opt} is required." unless options[opt]
@@ -118,15 +131,4 @@ class Kafka::Consumer
118
131
  end
119
132
  end
120
133
  end
121
-
122
- def create_config
123
- properties = java.util.Properties.new
124
- @properties.each do |k,v|
125
- k = k.to_s.gsub '_', '.'
126
- v = v.to_s
127
- properties.setProperty k, v
128
- end
129
- Java::KafkaConsumer::ConsumerConfig.new properties
130
- end
131
134
  end
132
-
@@ -1,5 +1,6 @@
1
1
  require 'jruby-kafka/namespace'
2
2
  require 'jruby-kafka/error'
3
+ require 'jruby-kafka/utility'
3
4
 
4
5
  # noinspection JRubyStringImportInspection
5
6
  class Kafka::KafkaProducer
@@ -7,25 +8,8 @@ class Kafka::KafkaProducer
7
8
  java_import 'org.apache.kafka.clients.producer.Callback'
8
9
  KAFKA_PRODUCER = Java::org.apache.kafka.clients.producer.KafkaProducer
9
10
 
10
- VALIDATIONS = {
11
- :'required.codecs' => %w[
12
- none gzip snappy lz4
13
- ]
14
- }
15
-
16
- REQUIRED = %w[
17
- bootstrap.servers key.serializer
18
- ]
19
-
20
- KNOWN = %w[
21
- acks batch.size block.on.buffer.full
22
- bootstrap.servers buffer.memory client.id
23
- compression.type key.serializer linger.ms
24
- max.in.flight.requests.per.connection max.request.size
25
- metadata.fetch.timeout.ms metadata.max.age.ms metric.reporters
26
- metrics.num.samples metrics.sample.window.ms receive.buffer.bytes
27
- reconnect.backoff.ms retries retry.backoff.ms
28
- send.buffer.bytes timeout.ms value.serializer
11
+ REQUIRED = [
12
+ :bootstrap_servers, :key_serializer
29
13
  ]
30
14
 
31
15
  class RubyCallback
@@ -43,18 +27,13 @@ class Kafka::KafkaProducer
43
27
  attr_reader :producer, :send_method, :send_cb_method, :options
44
28
 
45
29
  def initialize(opts = {})
46
- @options = opts.reduce({}) do |opts_array, (k, v)|
47
- unless v.nil?
48
- opts_array[k.to_s.gsub(/_/, '.')] = v
49
- end
50
- opts_array
51
- end
52
- validate_arguments
30
+ Kafka::Utility.validate_arguments REQUIRED, opts
31
+ @options = opts
53
32
  @send_method = @send_cb_method = proc { throw StandardError.new 'Producer is not connected' }
54
33
  end
55
34
 
56
35
  def connect
57
- @producer = KAFKA_PRODUCER.new(create_producer_config)
36
+ @producer = KAFKA_PRODUCER.new(Kafka::Utility.java_properties @options)
58
37
  @send_method = producer.java_method :send, [ProducerRecord]
59
38
  @send_cb_method = producer.java_method :send, [ProducerRecord, Callback.java_class]
60
39
  end
@@ -71,24 +50,4 @@ class Kafka::KafkaProducer
71
50
  def close
72
51
  @producer.close
73
52
  end
74
-
75
- private
76
-
77
- def validate_arguments
78
- errors = []
79
- missing = REQUIRED.reject { |opt| options[opt] }
80
- errors = ["Required settings: #{ missing.join(', ')}"] if missing.any?
81
- invalid = VALIDATIONS.reject { |opt, valid| options[opt].nil? or valid.include? options[opt].to_s }
82
- errors += invalid.map { |opt, valid| "#{ opt } should be one of: [#{ valid.join(', ')}]" }
83
- fail StandardError.new "Invalid configuration arguments: #{ errors.join('; ') }" if errors.any?
84
- options.keys.each do |opt|
85
- STDERR.puts "WARNING: Unknown configuration key: #{opt}" unless KNOWN.include? opt
86
- end
87
- end
88
-
89
- def create_producer_config
90
- properties = java.util.Properties.new
91
- options.each { |opt, value| properties.put opt, value.to_s }
92
- properties
93
- end
94
53
  end
@@ -1,6 +1,7 @@
1
1
  # basically we are porting this https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+Producer+Example
2
2
  require 'jruby-kafka/namespace'
3
3
  require 'jruby-kafka/error'
4
+ require 'jruby-kafka/utility'
4
5
 
5
6
  # noinspection JRubyStringImportInspection
6
7
  class Kafka::Producer
@@ -8,30 +9,9 @@ class Kafka::Producer
8
9
  java_import 'kafka.producer.ProducerConfig'
9
10
  java_import 'kafka.producer.KeyedMessage'
10
11
  KAFKA_PRODUCER = Java::kafka.javaapi.producer.Producer
11
- java_import 'kafka.message.NoCompressionCodec'
12
- java_import 'kafka.message.GZIPCompressionCodec'
13
- java_import 'kafka.message.SnappyCompressionCodec'
14
12
 
15
- VALIDATIONS = {
16
- :'request.required.acks' => %w[ 0 1 -1 ],
17
- :'required.codecs' => [NoCompressionCodec.name, GZIPCompressionCodec.name, SnappyCompressionCodec.name],
18
- :'producer.type' => %w[ sync async ]
19
- }
20
-
21
- REQUIRED = %w[
22
- metadata.broker.list
23
- ]
24
-
25
- # List of all available options extracted from http://kafka.apache.org/documentation.html#producerconfigs Apr. 27, 2014
26
- # If new options are added, they should just work. Please add them to the list so that we can get handy warnings.
27
- KNOWN = %w[
28
- metadata.broker.list request.required.acks request.timeout.ms
29
- producer.type serializer.class key.serializer.class
30
- partitioner.class compression.codec compressed.topics
31
- message.send.max.retries retry.backoff.ms topic.metadata.refresh.interval.ms
32
- queue.buffering.max.ms queue.buffering.max.messages queue.enqueue.timeout.ms
33
- batch.num.messages send.buffer.bytes client.id
34
- broker.list serializer.encoding
13
+ REQUIRED = [
14
+ :metadata_broker_list
35
15
  ]
36
16
 
37
17
  attr_reader :producer, :send_method, :options
@@ -41,27 +21,22 @@ class Kafka::Producer
41
21
  # options:
42
22
  # metadata_broker_list: ["localhost:9092"] - REQUIRED: a seed list of kafka brokers
43
23
  def initialize(opts = {})
44
- @options = opts.reduce({}) do |opts_array, (k, v)|
45
- unless v.nil?
46
- opts_array[k.to_s.gsub(/_/, '.')] = v
47
- end
48
- opts_array
24
+ @options = opts
25
+ if options[:broker_list]
26
+ options[:metadata_broker_list] = options.delete :broker_list
49
27
  end
50
- if options['broker.list']
51
- options['metadata.broker.list'] = options.delete 'broker.list'
28
+ if options[:metadata_broker_list].is_a? Array
29
+ options[:metadata_broker_list] = options[:metadata_broker_list].join(',')
52
30
  end
53
- if options['metadata.broker.list'].is_a? Array
54
- options['metadata.broker.list'] = options['metadata.broker.list'].join(',')
31
+ if options[:compressed_topics].is_a? Array
32
+ options[:compressed_topics] = options[:compressed_topics].join(',')
55
33
  end
56
- if options['compressed.topics'].is_a? Array
57
- options['compressed.topics'] = options['compressed.topics'].join(',')
58
- end
59
- validate_arguments
34
+ Kafka::Utility.validate_arguments REQUIRED, options
60
35
  @send_method = proc { throw StandardError.new 'Producer is not connected' }
61
36
  end
62
37
 
63
38
  def connect
64
- @producer = KAFKA_PRODUCER.new(create_producer_config)
39
+ @producer = KAFKA_PRODUCER.new(ProducerConfig.new Kafka::Utility.java_properties @options)
65
40
  @send_method = producer.java_method :send, [KeyedMessage]
66
41
  end
67
42
 
@@ -78,24 +53,4 @@ class Kafka::Producer
78
53
  def close
79
54
  @producer.close
80
55
  end
81
-
82
- private
83
-
84
- def validate_arguments
85
- errors = []
86
- missing = REQUIRED.reject { |opt| options[opt] }
87
- errors = ["Required settings: #{ missing.join(', ')}"] if missing.any?
88
- invalid = VALIDATIONS.reject { |opt, valid| options[opt].nil? or valid.include? options[opt].to_s }
89
- errors += invalid.map { |opt, valid| "#{ opt } should be one of: [#{ valid.join(', ')}]" }
90
- fail StandardError.new "Invalid configuration arguments: #{ errors.join('; ') }" if errors.any?
91
- options.keys.each do |opt|
92
- STDERR.puts "WARNING: Unknown configuration key: #{opt}" unless KNOWN.include? opt
93
- end
94
- end
95
-
96
- def create_producer_config
97
- properties = java.util.Properties.new
98
- options.each { |opt, value| properties.put opt, value.to_s }
99
- ProducerConfig.new(properties)
100
- end
101
56
  end
@@ -0,0 +1,20 @@
1
+ require 'java'
2
+ require 'jruby-kafka/namespace'
3
+
4
+ class Kafka::Utility
5
+ def self.java_properties(properties)
6
+ java_properties = java.util.Properties.new
7
+ properties.each do |k,v|
8
+ k = k.to_s.gsub '_', '.'
9
+ v = v.to_s
10
+ java_properties.setProperty k, v
11
+ end
12
+ java_properties
13
+ end
14
+
15
+ def self.validate_arguments(required_options, options)
16
+ required_options.each do |opt|
17
+ raise ArgumentError, "Parameter :#{opt} is required." unless options[opt]
18
+ end
19
+ end
20
+ end
data/lib/jruby-kafka.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'jruby-kafka/version'
2
1
  require 'jruby-kafka_jars.rb'
3
2
  require 'jruby-kafka/consumer'
4
3
  require 'jruby-kafka/producer'
5
4
  require 'jruby-kafka/kafka-producer'
5
+ require 'jruby-kafka/utility'
@@ -1,20 +1,20 @@
1
1
  # this is a generated file, to avoid over-writing it just delete this comment
2
2
  require 'jar_dependencies'
3
3
 
4
- require_jar( 'io.netty', 'netty', '3.7.0.Final' )
5
- require_jar( 'log4j', 'log4j', '1.2.17' )
6
- require_jar( 'net.sf.jopt-simple', 'jopt-simple', '3.2' )
7
- require_jar( 'org.xerial.snappy', 'snappy-java', '1.1.1.7' )
8
- require_jar( 'jline', 'jline', '0.9.94' )
9
- require_jar( 'org.slf4j', 'slf4j-api', '1.7.13' )
10
- require_jar( 'org.apache.kafka', 'kafka-clients', '0.8.2.2' )
11
- require_jar( 'org.apache.kafka', 'kafka_2.11', '0.8.2.2' )
12
- require_jar( 'org.scala-lang.modules', 'scala-xml_2.11', '1.0.2' )
13
- require_jar( 'junit', 'junit', '3.8.1' )
14
- require_jar( 'com.101tec', 'zkclient', '0.3' )
15
- require_jar( 'com.yammer.metrics', 'metrics-core', '2.2.0' )
16
4
  require_jar( 'org.scala-lang.modules', 'scala-parser-combinators_2.11', '1.0.2' )
5
+ require_jar( 'log4j', 'log4j', '1.2.17' )
17
6
  require_jar( 'org.scala-lang', 'scala-library', '2.11.5' )
18
7
  require_jar( 'org.apache.zookeeper', 'zookeeper', '3.4.6' )
19
8
  require_jar( 'org.slf4j', 'slf4j-log4j12', '1.7.13' )
9
+ require_jar( 'org.scala-lang.modules', 'scala-xml_2.11', '1.0.2' )
10
+ require_jar( 'org.slf4j', 'slf4j-api', '1.7.13' )
11
+ require_jar( 'io.netty', 'netty', '3.7.0.Final' )
12
+ require_jar( 'net.sf.jopt-simple', 'jopt-simple', '3.2' )
20
13
  require_jar( 'net.jpountz.lz4', 'lz4', '1.2.0' )
14
+ require_jar( 'junit', 'junit', '3.8.1' )
15
+ require_jar( 'org.apache.kafka', 'kafka-clients', '0.8.2.2' )
16
+ require_jar( 'com.yammer.metrics', 'metrics-core', '2.2.0' )
17
+ require_jar( 'org.apache.kafka', 'kafka_2.11', '0.8.2.2' )
18
+ require_jar( 'jline', 'jline', '0.9.94' )
19
+ require_jar( 'org.xerial.snappy', 'snappy-java', '1.1.1.7' )
20
+ require_jar( 'com.101tec', 'zkclient', '0.3' )
metadata CHANGED
@@ -1,72 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.1'
4
+ version: 2.2.2
5
5
  platform: java
6
6
  authors:
7
7
  - Joseph Lawson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - <
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jar-dependencies
14
29
  requirement: !ruby/object:Gem::Requirement
15
30
  requirements:
16
31
  - - ~>
17
32
  - !ruby/object:Gem::Version
18
33
  version: 0.3.2
19
- name: jar-dependencies
20
- prerelease: false
21
34
  type: :development
35
+ prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - ~>
25
39
  - !ruby/object:Gem::Version
26
40
  version: 0.3.2
27
41
  - !ruby/object:Gem::Dependency
42
+ name: rake
28
43
  requirement: !ruby/object:Gem::Requirement
29
44
  requirements:
30
45
  - - ~>
31
46
  - !ruby/object:Gem::Version
32
47
  version: '10.5'
33
- name: rake
34
- prerelease: false
35
48
  type: :development
49
+ prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ~>
39
53
  - !ruby/object:Gem::Version
40
54
  version: '10.5'
41
55
  - !ruby/object:Gem::Dependency
56
+ name: rspec
42
57
  requirement: !ruby/object:Gem::Requirement
43
58
  requirements:
44
59
  - - ~>
45
60
  - !ruby/object:Gem::Version
46
61
  version: '3.4'
47
- name: rspec
48
- prerelease: false
49
62
  type: :development
63
+ prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ~>
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.4'
55
69
  - !ruby/object:Gem::Dependency
70
+ name: ruby-maven
56
71
  requirement: !ruby/object:Gem::Requirement
57
72
  requirements:
58
73
  - - ~>
59
74
  - !ruby/object:Gem::Version
60
75
  version: '3.3'
61
- name: ruby-maven
62
- prerelease: false
63
76
  type: :development
77
+ prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ~>
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.3'
69
- description: this is primarily to be used as an interface for logstash
83
+ description: A ready to go interface to Kafka for JRuby.
70
84
  email:
71
85
  - joe@joekiller.com
72
86
  executables: []
@@ -83,7 +97,7 @@ files:
83
97
  - lib/jruby-kafka/kafka-producer.rb
84
98
  - lib/jruby-kafka/namespace.rb
85
99
  - lib/jruby-kafka/producer.rb
86
- - lib/jruby-kafka/version.rb
100
+ - lib/jruby-kafka/utility.rb
87
101
  - lib/jruby-kafka_jars.rb
88
102
  - lib/junit/junit/3.8.1/junit-3.8.1.jar
89
103
  - lib/log4j/log4j/1.2.17/log4j-1.2.17.jar
@@ -102,26 +116,26 @@ homepage: https://github.com/joekiller/jruby-kafka
102
116
  licenses:
103
117
  - Apache 2.0
104
118
  metadata: {}
105
- post_install_message:
119
+ post_install_message:
106
120
  rdoc_options: []
107
121
  require_paths:
108
122
  - lib
109
123
  required_ruby_version: !ruby/object:Gem::Requirement
110
124
  requirements:
111
- - - '>='
125
+ - - ! '>='
112
126
  - !ruby/object:Gem::Version
113
127
  version: '0'
114
128
  required_rubygems_version: !ruby/object:Gem::Requirement
115
129
  requirements:
116
- - - '>='
130
+ - - ! '>='
117
131
  - !ruby/object:Gem::Version
118
132
  version: '0'
119
133
  requirements:
120
134
  - jar 'org.apache.kafka:kafka_2.11', '0.8.2.2'
121
135
  - jar 'org.slf4j:slf4j-log4j12', '1.7.13'
122
- rubyforge_project:
136
+ rubyforge_project:
123
137
  rubygems_version: 2.4.5
124
- signing_key:
138
+ signing_key:
125
139
  specification_version: 4
126
140
  summary: jruby Kafka wrapper
127
141
  test_files: []
@@ -1,4 +0,0 @@
1
- module Kafka
2
- VERSION = '2.1'.freeze
3
- JAR_DEPENDENCIES_VERSION = '0.3.2'.freeze
4
- end