rdkafka 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rdkafka/ffi.rb +1 -0
- data/lib/rdkafka/message.rb +2 -1
- data/lib/rdkafka/version.rb +1 -1
- data/spec/rdkafka/message_spec.rb +4 -0
- data/spec/rdkafka/producer_spec.rb +52 -0
- data/spec/spec_helper.rb +4 -4
- 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: 8d6da9327e4ab83441c784ccb89783e0928821e6
|
4
|
+
data.tar.gz: b6812cb4eee125203fd73efa1904b63bb0670d31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b155e6b7d3358ba451ba88ce6bde6cf327ff7db26275b76b1c24d6010b0f015eef7df26acf5362230872163ea62444919164e3f1e79f04d8c3093932b53e6e60
|
7
|
+
data.tar.gz: 01d58aed27bc1f385c2d3bcb22e964ceff47c0582c3bccc3e6af6f88d2c4806ea3c3d0035d0b52d45522a3924722a506d97e1986b4f7babe558619cbfc9ed3ba
|
data/lib/rdkafka/ffi.rb
CHANGED
@@ -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
|
|
data/lib/rdkafka/message.rb
CHANGED
@@ -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
|
data/lib/rdkafka/version.rb
CHANGED
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -5,8 +5,7 @@ require "rdkafka"
|
|
5
5
|
def rdkafka_config
|
6
6
|
config = {
|
7
7
|
:"bootstrap.servers" => "localhost:9092",
|
8
|
-
:"group.id" => "
|
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 &&
|
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.
|
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-
|
11
|
+
date: 2017-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|