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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72692497af5d422995313c36700af4b0cb832411
4
- data.tar.gz: da5d00bd780a496573cb007a32d6b1e5bea2a775
3
+ metadata.gz: 715896bb3f1ca4df3d5d05a24697606eb0d219ca
4
+ data.tar.gz: 18e6d31572fcf45e2f91065a032d2273c617adda
5
5
  SHA512:
6
- metadata.gz: 2bf5ce855f661db9117bf622de88de8d45233f07c1d3c21282b73052c640cee7d0d86212946301fe21865623955ffa3cb47312927022021e08c66a2b3625acf2
7
- data.tar.gz: de6b0f7ea494ecc23d1cc95d0e12516aba88f38aa08ed99613ef008dc753bc805147aa7f91768ce90b462eafea9eae4661340f4d9d1185532092e62a4457428d
6
+ metadata.gz: 43d22cb06fe0afe4afec0a20cee94b97ebe1698143038a1e36361dfa45226938a2db96cf6cb54bce9fa5c0c6445a3855409050b6d6ebe9adb46278ff48569e46
7
+ data.tar.gz: c939700ce7d662f39210e02c389ae900d11ac57742ce5cb5d593ee17bded4a645341b094d94fe66c46eb526c92f8970ec32c23546bb7eb22817875b02dcb3b24
@@ -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, 3);
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' */
@@ -96,6 +96,7 @@ typedef struct HermannInstanceConfig {
96
96
  int isConnected;
97
97
 
98
98
  int isErrored;
99
+
99
100
  char *error;
100
101
  } HermannInstanceConfig;
101
102
 
@@ -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] :brokers (for MRI) Comma separated list of brokers
21
- # @option opts [Integer] :partition (for MRI) The kafka partition
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]
@@ -24,6 +24,9 @@ module Hermann
24
24
 
25
25
  # cannot discover brokers from zookeeper
26
26
  class NoBrokersError < GeneralError; end
27
+
28
+ # offsets can only be two symbols or a fixnum
29
+ class InvalidOffsetError < GeneralError; end
27
30
  end
28
31
  end
29
32
 
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.236
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-28 00:00:00.000000000 Z
13
+ date: 2015-04-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby