hermann 0.23.0.236 → 0.23.0.240

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTY5YjNkMzk4YWIwY2Q2MzJmYjYxODBjMmU1YTA1YzYwNDE1YzBlMg==
4
+ YmI3YjVlZTYxZDYwOTUzYmRiM2IzZjJlNjJlNGU4NzczMDFhMjhjYg==
5
5
  data.tar.gz: !binary |-
6
- NWVlZjNiMTdjOTkzNjljMDRkN2M5NTg4MjY5YTUyNTgwYzMwMzhjNQ==
6
+ Y2VmZjViOWM3NzdmM2E4NTEyODQxMzY4Njc2NzYyYjc3ODIzN2UyNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2YyNmJhMTg0YjA4ZmI4ZDlhNWIzYjNhMGU2ZjYzNTVlYzMzZGY1YThhZGRk
10
- OGM1MTM2ODk3OTUxZDg1NmQ5NjM5YjNhM2VhMWIxNTk3MzM4MTM4NGNkNWFm
11
- MTJkNmJhNzFiNjhkNmYxZGM5NjAxN2Q5MThkNTcwNjBlMzgwMzY=
9
+ YTZlZGJkODEwM2NlYWIyZDIxNjExZTJiMWM4YjQ4YTY1YmVmZDg0NDBiNWRk
10
+ NTAzNTgwMTA4M2JhNmRiYjNiNzUzMzk5NzllNGE3OTM3NmQyNjg2YzIzOTA1
11
+ ZjJhZmIwZTE2MzEwZTBkZjJkNTNkZmE1MjI5NDBmN2Q2MzBlYTc=
12
12
  data.tar.gz: !binary |-
13
- NzJkYmI3YzM1MjI4NzUzZWZiYTA2ZTFmNzhjZjE4ZGUxNTU4ZGRmZmEyOThk
14
- MTIzMzY4MmIzODYyZTY1YjZjMDZlODM0OWU1OTI5NWMwYTFiZjA5YjU1NjAy
15
- YTI5NzlmMWUwNThhMmY0MjRmNjU3Yzk4NWM1MGNkZjMwZTcxNTU=
13
+ ZDU5NDc5YjVjOTljNjUyYjIwOGNiOTVkYWFjYjEzYmE2NzAyOWZhZTQxNDRk
14
+ ZWE5ODAzMDhkOTU2OWNjYjczOWRkMDYzY2I4MzYyZDQ5ZWMxMTFkYWNjOGRi
15
+ YjZlNGM4ZTU2ZGQzMjVjNWM2ZGY1ZGMyNWYwNjhhNzA2NDE4NzU=
@@ -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.240
5
5
  platform: ruby
6
6
  authors:
7
7
  - R. Tyler Croy