hermann 0.23.0.236-java → 0.23.0.242-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/hermann/hermann_lib.c +15 -5
- data/ext/hermann/hermann_lib.h +1 -0
- data/lib/hermann/consumer.rb +15 -3
- data/lib/hermann/errors.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 715896bb3f1ca4df3d5d05a24697606eb0d219ca
|
4
|
+
data.tar.gz: 18e6d31572fcf45e2f91065a032d2273c617adda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43d22cb06fe0afe4afec0a20cee94b97ebe1698143038a1e36361dfa45226938a2db96cf6cb54bce9fa5c0c6445a3855409050b6d6ebe9adb46278ff48569e46
|
7
|
+
data.tar.gz: c939700ce7d662f39210e02c389ae900d11ac57742ce5cb5d593ee17bded4a645341b094d94fe66c46eb526c92f8970ec32c23546bb7eb22817875b02dcb3b24
|
data/ext/hermann/hermann_lib.c
CHANGED
@@ -321,9 +321,6 @@ void consumer_init_kafka(HermannInstanceConfig* config) {
|
|
321
321
|
rd_kafka_set_logger(config->rk, logger);
|
322
322
|
rd_kafka_set_log_level(config->rk, LOG_DEBUG);
|
323
323
|
|
324
|
-
/* TODO: offset calculation */
|
325
|
-
config->start_offset = RD_KAFKA_OFFSET_END;
|
326
|
-
|
327
324
|
/* Add brokers */
|
328
325
|
if (rd_kafka_brokers_add(config->rk, config->brokers) == 0) {
|
329
326
|
fprintf(stderr, "%% No valid brokers specified\n");
|
@@ -820,11 +817,13 @@ static VALUE consumer_allocate(VALUE klass) {
|
|
820
817
|
* @param topic VALUE a Ruby string
|
821
818
|
* @param brokers VALUE a Ruby string containing list of host:port
|
822
819
|
* @param partition VALUE a Ruby number
|
820
|
+
* @param offset VALUE a Ruby number
|
823
821
|
*/
|
824
822
|
static VALUE consumer_initialize(VALUE self,
|
825
823
|
VALUE topic,
|
826
824
|
VALUE brokers,
|
827
|
-
VALUE partition
|
825
|
+
VALUE partition,
|
826
|
+
VALUE offset) {
|
828
827
|
|
829
828
|
HermannInstanceConfig* consumerConfig;
|
830
829
|
char* topicPtr;
|
@@ -845,6 +844,17 @@ static VALUE consumer_initialize(VALUE self,
|
|
845
844
|
consumerConfig->exit_eof = 0;
|
846
845
|
consumerConfig->quiet = 0;
|
847
846
|
|
847
|
+
if ( FIXNUM_P(offset) ) {
|
848
|
+
consumerConfig->start_offset = FIX2LONG(offset);
|
849
|
+
} else if ( SYMBOL_P(offset) ) {
|
850
|
+
if ( offset == ID2SYM(rb_intern("start")) )
|
851
|
+
consumerConfig->start_offset = RD_KAFKA_OFFSET_BEGINNING;
|
852
|
+
else if ( offset == ID2SYM(rb_intern("end")) )
|
853
|
+
consumerConfig->start_offset = RD_KAFKA_OFFSET_END;
|
854
|
+
} else {
|
855
|
+
consumerConfig->start_offset = RD_KAFKA_OFFSET_END;
|
856
|
+
}
|
857
|
+
|
848
858
|
return self;
|
849
859
|
}
|
850
860
|
|
@@ -1033,7 +1043,7 @@ void Init_hermann_lib() {
|
|
1033
1043
|
rb_define_alloc_func(c_consumer, consumer_allocate);
|
1034
1044
|
|
1035
1045
|
/* Initialize */
|
1036
|
-
rb_define_method(c_consumer, "initialize", consumer_initialize,
|
1046
|
+
rb_define_method(c_consumer, "initialize", consumer_initialize, 4);
|
1037
1047
|
rb_define_method(c_consumer, "initialize_copy", consumer_init_copy, 1);
|
1038
1048
|
|
1039
1049
|
/* Consumer has method 'consume' */
|
data/ext/hermann/hermann_lib.h
CHANGED
data/lib/hermann/consumer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hermann'
|
2
|
+
require 'hermann/errors'
|
2
3
|
|
3
4
|
if Hermann.jruby?
|
4
5
|
require 'hermann/provider/java_simple_consumer'
|
@@ -17,13 +18,18 @@ module Hermann
|
|
17
18
|
#
|
18
19
|
# @params [String] kafka topic
|
19
20
|
# @params [Hash] options for Consumer
|
20
|
-
# @option opts [String]
|
21
|
-
# @option opts [Integer]
|
21
|
+
# @option opts [String] :brokers (for MRI) Comma separated list of brokers
|
22
|
+
# @option opts [Integer] :partition (for MRI) The kafka partition
|
23
|
+
# @option opts [Symbol|Fixnum] :offset (for MRI) Starting consumer offset. either :start, :end, or Fixnum
|
22
24
|
# @option opts [Integer] :zookeepers (for jruby) list of zookeeper servers
|
23
25
|
# @option opts [Integer] :group_id (for jruby) client group_id
|
24
26
|
#
|
25
27
|
def initialize(topic, opts = {})
|
26
28
|
@topic = topic
|
29
|
+
|
30
|
+
offset = opts.delete(:offset)
|
31
|
+
raise Hermann::Errors::InvalidOffsetError.new("Bad offset: #{offset}") unless valid_offset?(offset)
|
32
|
+
|
27
33
|
if Hermann.jruby?
|
28
34
|
zookeepers, group_id = require_values_at(opts, :zookeepers, :group_id)
|
29
35
|
|
@@ -31,7 +37,7 @@ module Hermann
|
|
31
37
|
else
|
32
38
|
brokers, partition = require_values_at(opts, :brokers, :partition)
|
33
39
|
|
34
|
-
@internal = Hermann::Lib::Consumer.new(topic, brokers, partition)
|
40
|
+
@internal = Hermann::Lib::Consumer.new(topic, brokers, partition, offset)
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
@@ -49,6 +55,12 @@ module Hermann
|
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
58
|
+
private
|
59
|
+
|
60
|
+
def valid_offset?(offset)
|
61
|
+
offset.nil? || offset.is_a?(Fixnum) || offset == :start || offset == :end
|
62
|
+
end
|
63
|
+
|
52
64
|
def require_values_at(opts, *args)
|
53
65
|
args.map do |a|
|
54
66
|
raise "Please provide :#{a} option!" unless opts[a]
|
data/lib/hermann/errors.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hermann
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.23.0.
|
4
|
+
version: 0.23.0.242
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- R. Tyler Croy
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-04-
|
13
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: concurrent-ruby
|