jruby-kafka 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jruby-kafka/producer.rb +130 -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: b854790fa9d012c35cb74d4ca6b6db7f5c568a2f
|
4
|
+
data.tar.gz: 5f98478a4cfc09730a1ce092108d72798b6e8075
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b46e5f6cfa518c2b91a614b956d0a617d066aa80922c391ea1fa298f987e466b5a3199c5f97ff86f31cbcb5081f1e04786f836754d10f27b0d4ce8d93c183cb6
|
7
|
+
data.tar.gz: 69ea85ee730a74ccb3b7e3159701d090c521d301663d4ac9cd4dbc6cfeff6bc5c352d8fceea2530c68faa7d7438f8cd8a895faed3a5b25d7a9a8d9376424cecc
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# basically we are porting this https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+Producer+Example
|
2
|
+
|
3
|
+
require "java"
|
4
|
+
|
5
|
+
require "jruby-kafka/namespace"
|
6
|
+
require "jruby-kafka/error"
|
7
|
+
|
8
|
+
java_import 'org.I0Itec.zkclient.exception.ZkException'
|
9
|
+
|
10
|
+
class Kafka::Producer
|
11
|
+
@topic
|
12
|
+
@zk_connect
|
13
|
+
|
14
|
+
# Create a Kafka Producer
|
15
|
+
#
|
16
|
+
# options:
|
17
|
+
# :zk_connect => "localhost:2181" - REQUIRED: The connection string for the
|
18
|
+
# zookeeper connection in the form host:port. Multiple URLS can be given to allow fail-over.
|
19
|
+
# :zk_connect_timeout => "6000" - (optional) The max time that the client waits while establishing a connection to zookeeper.
|
20
|
+
# :topic_id => "topic" - REQUIRED: The topic id to consume on.
|
21
|
+
# :broker_list => "localhost:9092" - REQUIRED: a seed list of kafka brokers
|
22
|
+
def initialize(options={})
|
23
|
+
validate_required_arguments(options)
|
24
|
+
|
25
|
+
@zk_connect = options[:zk_connect]
|
26
|
+
@topic = options[:topic_id]
|
27
|
+
@brokers = options[:broker_list]
|
28
|
+
@zk_session_timeout = '6000'
|
29
|
+
@zk_connect_timeout = '6000'
|
30
|
+
@zk_sync_time = '2000'
|
31
|
+
@auto_offset_reset = 'largest'
|
32
|
+
@auto_commit_interval = '1000'
|
33
|
+
@running = false
|
34
|
+
@rebalance_max_retries = '4'
|
35
|
+
@rebalance_backoff_ms = '2000'
|
36
|
+
@socket_timeout_ms = "#{30 * 1000}"
|
37
|
+
@socket_receive_buffer_bytes = "#{64 * 1024}"
|
38
|
+
@auto_commit_enable = "#{true}"
|
39
|
+
@queued_max_message_chunks = '10'
|
40
|
+
@refresh_leader_backoff_ms = '200'
|
41
|
+
@consumer_timeout_ms = '-1'
|
42
|
+
|
43
|
+
if options[:zk_connect_timeout]
|
44
|
+
@zk_connect_timeout = "#{options[:zk_connect_timeout]}"
|
45
|
+
end
|
46
|
+
if options[:zk_session_timeout]
|
47
|
+
@zk_session_timeout = "#{options[:zk_session_timeout]}"
|
48
|
+
end
|
49
|
+
if options[:zk_sync_time]
|
50
|
+
@zk_sync_time = "#{options[:zk_sync_time]}"
|
51
|
+
end
|
52
|
+
if options[:auto_commit_interval]
|
53
|
+
@auto_commit_interval = "#{options[:auto_commit_interval]}"
|
54
|
+
end
|
55
|
+
|
56
|
+
if options[:rebalance_max_retries]
|
57
|
+
@rebalance_max_retries = "#{options[:rebalance_max_retries]}"
|
58
|
+
end
|
59
|
+
|
60
|
+
if options[:rebalance_backoff_ms]
|
61
|
+
@rebalance_backoff_ms = "#{options[:rebalance_backoff_ms]}"
|
62
|
+
end
|
63
|
+
|
64
|
+
if options[:socket_timeout_ms]
|
65
|
+
@socket_timeout_ms = "#{options[:socket_timeout_ms]}"
|
66
|
+
end
|
67
|
+
|
68
|
+
if options[:socket_receive_buffer_bytes]
|
69
|
+
@socket_receive_buffer_bytes = "#{options[:socket_receive_buffer_bytes]}"
|
70
|
+
end
|
71
|
+
|
72
|
+
if options[:auto_commit_enable]
|
73
|
+
@auto_commit_enable = "#{options[:auto_commit_enable]}"
|
74
|
+
end
|
75
|
+
|
76
|
+
if options[:refresh_leader_backoff_ms]
|
77
|
+
@refresh_leader_backoff_ms = "#{options[:refresh_leader_backoff_ms]}"
|
78
|
+
end
|
79
|
+
|
80
|
+
if options[:consumer_timeout_ms]
|
81
|
+
@consumer_timeout_ms = "#{options[:consumer_timeout_ms]}"
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def validate_required_arguments(options={})
|
88
|
+
[:zk_connect, :broker_list, :topic_id].each do |opt|
|
89
|
+
raise(ArgumentError, "#{opt} is required.") unless options[opt]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
public
|
94
|
+
def shutdown()
|
95
|
+
@running = false
|
96
|
+
end
|
97
|
+
|
98
|
+
public
|
99
|
+
def connect()
|
100
|
+
@producer = Java::kafka::producer::Producer.new(createProducerConfig)
|
101
|
+
end
|
102
|
+
|
103
|
+
public
|
104
|
+
def sendMsg(key,msg)
|
105
|
+
m = Java::kafka::producer::KeyedMessage.new(topic=@topic,key=key, message=msg)
|
106
|
+
#the send message for a producer is scala varargs, which doesn't seem to play nice w/ jruby
|
107
|
+
# this is the best I could come up with
|
108
|
+
ms = Java::scala::collection::immutable::Vector.new(0,0,0)
|
109
|
+
ms = ms.append_front(m)
|
110
|
+
@producer.send(ms)
|
111
|
+
end
|
112
|
+
|
113
|
+
public
|
114
|
+
def running?
|
115
|
+
@running
|
116
|
+
end
|
117
|
+
|
118
|
+
def createProducerConfig()
|
119
|
+
# TODO lots more options avaiable here: http://kafka.apache.org/documentation.html#producerconfigs
|
120
|
+
properties = java.util.Properties.new()
|
121
|
+
properties.put("zookeeper.connect", @zk_connect)
|
122
|
+
properties.put("zookeeper.connection.timeout.ms", @zk_connect_timeout)
|
123
|
+
properties.put("zookeeper.session.timeout.ms", @zk_session_timeout)
|
124
|
+
properties.put("zookeeper.sync.time.ms", @zk_sync_time)
|
125
|
+
properties.put("serializer.class", "kafka.serializer.StringEncoder")
|
126
|
+
properties.put("request.required.acks", "1")
|
127
|
+
properties.put("metadata.broker.list", @brokers)
|
128
|
+
return Java::kafka::producer::ProducerConfig.new(properties)
|
129
|
+
end
|
130
|
+
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: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Lawson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: this is primarily to be used as an interface for logstash
|
14
14
|
email:
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/jruby-kafka/error.rb
|
26
26
|
- lib/jruby-kafka/group.rb
|
27
27
|
- lib/jruby-kafka/namespace.rb
|
28
|
+
- lib/jruby-kafka/producer.rb
|
28
29
|
homepage: https://github.com/joekiller/jruby-kafka
|
29
30
|
licenses:
|
30
31
|
- Apache 2.0
|