jruby-kafka 1.3.0-java → 1.4.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jruby-kafka/kafka-producer.rb +76 -0
- data/lib/jruby-kafka.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a5fbbd24312699a8ecebe3875234e202c20fc0b
|
4
|
+
data.tar.gz: 7c6f1a9a2085ec7574797fc79c29cd0f7eacd8e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f52d35afd1daa035e48f5bd8da20c12e13d01ae51b8e31314dc9cb3905f47be1feef1e642c06a2e425e7e8c863c46ffd8ebcddaf0bcac7a621efdc1092769311
|
7
|
+
data.tar.gz: 528e5846605ec8d144174f6de4157e5f1ec06619c4fd7b2fc9be9a74bf5c076ae4508d43d6e04b73f831c7bd27b2d88042da2a5a37e271da139f7d67afc6bfa5
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'jruby-kafka/namespace'
|
2
|
+
require 'jruby-kafka/error'
|
3
|
+
|
4
|
+
# noinspection JRubyStringImportInspection
|
5
|
+
class Kafka::KafkaProducer
|
6
|
+
java_import 'org.apache.kafka.clients.producer.ProducerRecord'
|
7
|
+
KAFKA_PRODUCER = Java::org.apache.kafka.clients.producer.KafkaProducer
|
8
|
+
|
9
|
+
VALIDATIONS = {
|
10
|
+
:'required.codecs' => %w[
|
11
|
+
none gzip snappy lz4
|
12
|
+
]
|
13
|
+
}
|
14
|
+
|
15
|
+
REQUIRED = %w[
|
16
|
+
bootstrap.servers key.serializer
|
17
|
+
]
|
18
|
+
|
19
|
+
KNOWN = %w[
|
20
|
+
acks batch.size block.on.buffer.full
|
21
|
+
bootstrap.servers buffer.memory client.id
|
22
|
+
compression.type key.serializer linger.ms
|
23
|
+
max.in.flight.requests.per.connection max.request.size
|
24
|
+
metadata.fetch.timeout.ms metadata.max.age.ms metric.reporters
|
25
|
+
metrics.num.samples metrics.sample.window.ms receive.buffer.bytes
|
26
|
+
reconnect.backoff.ms retries retry.backoff.ms
|
27
|
+
send.buffer.bytes timeout.ms value.serializer
|
28
|
+
]
|
29
|
+
|
30
|
+
attr_reader :producer, :send_method, :options
|
31
|
+
|
32
|
+
def initialize(opts = {})
|
33
|
+
@options = opts.reduce({}) do |opts_array, (k, v)|
|
34
|
+
unless v.nil?
|
35
|
+
opts_array[k.to_s.gsub(/_/, '.')] = v
|
36
|
+
end
|
37
|
+
opts_array
|
38
|
+
end
|
39
|
+
validate_arguments
|
40
|
+
@send_method = proc { throw StandardError.new 'Producer is not connected' }
|
41
|
+
end
|
42
|
+
|
43
|
+
def connect
|
44
|
+
@producer = KAFKA_PRODUCER.new(create_producer_config)
|
45
|
+
@send_method = producer.java_method :send, [ProducerRecord]
|
46
|
+
end
|
47
|
+
|
48
|
+
# throws FailedToSendMessageException or if not connected, StandardError.
|
49
|
+
def send_msg(topic, partition, key, value)
|
50
|
+
send_method.call(ProducerRecord.new(topic, partition, key, value))
|
51
|
+
end
|
52
|
+
|
53
|
+
def close
|
54
|
+
@producer.close
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def validate_arguments
|
60
|
+
errors = []
|
61
|
+
missing = REQUIRED.reject { |opt| options[opt] }
|
62
|
+
errors = ["Required settings: #{ missing.join(', ')}"] if missing.any?
|
63
|
+
invalid = VALIDATIONS.reject { |opt, valid| options[opt].nil? or valid.include? options[opt].to_s }
|
64
|
+
errors += invalid.map { |opt, valid| "#{ opt } should be one of: [#{ valid.join(', ')}]" }
|
65
|
+
fail StandardError.new "Invalid configuration arguments: #{ errors.join('; ') }" if errors.any?
|
66
|
+
options.keys.each do |opt|
|
67
|
+
STDERR.puts "WARNING: Unknown configuration key: #{opt}" unless KNOWN.include? opt
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_producer_config
|
72
|
+
properties = java.util.Properties.new
|
73
|
+
options.each { |opt, value| properties.put opt, value.to_s }
|
74
|
+
properties
|
75
|
+
end
|
76
|
+
end
|
data/lib/jruby-kafka.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby-kafka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Joseph Lawson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/jruby-kafka/consumer.rb
|
72
72
|
- lib/jruby-kafka/error.rb
|
73
73
|
- lib/jruby-kafka/group.rb
|
74
|
+
- lib/jruby-kafka/kafka-producer.rb
|
74
75
|
- lib/jruby-kafka/namespace.rb
|
75
76
|
- lib/jruby-kafka/producer.rb
|
76
77
|
- lib/jruby-kafka_jars.rb
|