rdkafka 0.1.10 → 0.1.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47ed8b2e877ccd9b0d4f79e6c252651f497b3aad
4
- data.tar.gz: 274091ba3bf02e06444c871c7ed4af50e417be08
3
+ metadata.gz: 8d6da9327e4ab83441c784ccb89783e0928821e6
4
+ data.tar.gz: b6812cb4eee125203fd73efa1904b63bb0670d31
5
5
  SHA512:
6
- metadata.gz: ea30c37519e22b12c8ffb38fc902ccb9cb4c2fb2ef5432aa91df5aa116c5abab5965cd0787c6de76a4f664dad7d7b97753895d5ae27852374cbae1b889245d96
7
- data.tar.gz: e49e57f8ccd45d62250f2eef6e2a6da3f9ea90b3393239f2b2d82222adfb3bbecd6927fce42adaae6e16bca9ee1dc25e69d7a3b25942edb6f19aa5594524b710
6
+ metadata.gz: b155e6b7d3358ba451ba88ce6bde6cf327ff7db26275b76b1c24d6010b0f015eef7df26acf5362230872163ea62444919164e3f1e79f04d8c3093932b53e6e60
7
+ data.tar.gz: 01d58aed27bc1f385c2d3bcb22e964ceff47c0582c3bccc3e6af6f88d2c4806ea3c3d0035d0b52d45522a3924722a506d97e1986b4f7babe558619cbfc9ed3ba
@@ -35,6 +35,7 @@ module Rdkafka
35
35
  end
36
36
 
37
37
  attach_function :rd_kafka_message_destroy, [:pointer], :void
38
+ attach_function :rd_kafka_message_timestamp, [:pointer, :pointer], :int64
38
39
  attach_function :rd_kafka_topic_new, [:pointer, :string, :pointer], :pointer
39
40
  attach_function :rd_kafka_topic_name, [:pointer], :string
40
41
 
@@ -1,6 +1,6 @@
1
1
  module Rdkafka
2
2
  class Message
3
- attr_reader :topic, :partition, :payload, :key, :offset
3
+ attr_reader :topic, :partition, :payload, :key, :offset, :timestamp
4
4
 
5
5
  def initialize(native_message)
6
6
  unless native_message[:rkt].null?
@@ -14,6 +14,7 @@ module Rdkafka
14
14
  @key = native_message[:key].read_string(native_message[:key_len])
15
15
  end
16
16
  @offset = native_message[:offset]
17
+ @timestamp = FFI.rd_kafka_message_timestamp(native_message, nil)
17
18
  end
18
19
 
19
20
  def to_s
@@ -1,4 +1,4 @@
1
1
  module Rdkafka
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  LIBRDKAFKA_VERSION = "0.11.0"
4
4
  end
@@ -70,4 +70,8 @@ describe Rdkafka::Message do
70
70
  it "should have an offset" do
71
71
  expect(subject.offset).to eq 100
72
72
  end
73
+
74
+ it "should have a timestamp" do
75
+ expect(subject.timestamp).to be > 0
76
+ end
73
77
  end
@@ -38,6 +38,58 @@ describe Rdkafka::Producer do
38
38
  expect(message.partition).to eq 0
39
39
  expect(message.payload).to eq "payload 1"
40
40
  expect(message.key).to eq "key 1"
41
+ # Since api.version.request is on by default we will get
42
+ # the message creation timestamp if it's not set.
43
+ expect(message.timestamp).to be > 1505069891557
44
+ end
45
+
46
+ it "should produce a message with utf-8 encoding" do
47
+ handle = producer.produce(
48
+ topic: "produce_test_topic",
49
+ payload: "Τη γλώσσα μου έδωσαν ελληνική",
50
+ key: "key utf8"
51
+ )
52
+ expect(handle.pending?).to be true
53
+
54
+ # Check delivery handle and report
55
+ report = handle.wait(5)
56
+
57
+ # Close producer
58
+ producer.close
59
+
60
+ # Consume message and verify it's content
61
+ message = wait_for_message(
62
+ topic: "produce_test_topic",
63
+ delivery_report: report
64
+ )
65
+
66
+ expect(message.payload.force_encoding("utf-8")).to eq "Τη γλώσσα μου έδωσαν ελληνική"
67
+ expect(message.key).to eq "key utf8"
68
+ end
69
+
70
+ it "should produce a message with a timestamp" do
71
+ handle = producer.produce(
72
+ topic: "produce_test_topic",
73
+ payload: "Payload 1",
74
+ key: "key timestamp",
75
+ timestamp: 1505069646000
76
+ )
77
+ expect(handle.pending?).to be true
78
+
79
+ # Check delivery handle and report
80
+ report = handle.wait(5)
81
+
82
+ # Close producer
83
+ producer.close
84
+
85
+ # Consume message and verify it's content
86
+ message = wait_for_message(
87
+ topic: "produce_test_topic",
88
+ delivery_report: report
89
+ )
90
+
91
+ expect(message.key).to eq "key timestamp"
92
+ expect(message.timestamp).to eq 1505069646000
41
93
  end
42
94
 
43
95
  it "should raise a timeout error when waiting too long" do
@@ -5,8 +5,7 @@ require "rdkafka"
5
5
  def rdkafka_config
6
6
  config = {
7
7
  :"bootstrap.servers" => "localhost:9092",
8
- :"group.id" => "ruby_test",
9
- :"client.id" => "test",
8
+ :"group.id" => "ruby-test-#{Random.new.rand(0..1_000_000)}",
10
9
  :"auto.offset.reset" => "earliest",
11
10
  :"enable.partition.eof" => false
12
11
  }
@@ -24,7 +23,6 @@ def native_client
24
23
  end
25
24
 
26
25
  def wait_for_message(topic:, delivery_report:, timeout_in_seconds: 30)
27
- offset = delivery_report.offset - 1
28
26
  consumer = rdkafka_config.consumer
29
27
  consumer.subscribe(topic)
30
28
  timeout = Time.now.to_i + timeout_in_seconds
@@ -33,7 +31,9 @@ def wait_for_message(topic:, delivery_report:, timeout_in_seconds: 30)
33
31
  raise "Timeout of #{timeout_in_seconds} seconds reached in wait_for_message"
34
32
  end
35
33
  message = consumer.poll(100)
36
- if message && message.offset == offset
34
+ if message &&
35
+ message.partition == delivery_report.partition &&
36
+ message.offset == delivery_report.offset - 1
37
37
  return message
38
38
  end
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdkafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thijs Cadier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-04 00:00:00.000000000 Z
11
+ date: 2017-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi