kafka_rest_client 0.3.0 → 0.4.0
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 +4 -4
- data/README.md +5 -1
- data/kafka_rest_client.gemspec +1 -1
- data/lib/kafka_rest_client/avro_producer.rb +18 -1
- data/lib/kafka_rest_client/configuration.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0369a154f21c09aa1d3946e42c6ef83835ab3f72
|
4
|
+
data.tar.gz: 3b8bdd2fafd712f45754739eb4914f33c5ed9642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7fe499236fab1d5fd616dcb467282b7a0aa41fa9098d9eab317351a54df283b468d525f37abcd011fd78ca236b0b38e636352770bd2c71327281780c5398274
|
7
|
+
data.tar.gz: 743eb70e8f1bac3bc53a7ef0beda1590e7434677b25bebfc34b67081a65d42c7e464576515ddacb5515f81300a5371f64c4c9c1b78c6297dc928e7439fad3fe5
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A Ruby client to interact with [Kafka REST Proxy](http://docs.confluent.io/1.0.1/kafka-rest/docs/index.html)
|
4
4
|
|
5
|
-
**Current Version:** 0.
|
5
|
+
**Current Version:** 0.4.0
|
6
6
|
|
7
7
|
**Supported Ruby versions:** 2.0, 2.1, 2.2
|
8
8
|
|
@@ -39,6 +39,10 @@ producer = KafkaRestClient::AvroProducer.new
|
|
39
39
|
# with the "#{topic}-value" name
|
40
40
|
producer.produce('ice-cream-melted', { temperature: 35, unit: 'celsius' })
|
41
41
|
|
42
|
+
# Produce an event using the topic name, payload and a partition key
|
43
|
+
# The partition key should be the name of a field in the message
|
44
|
+
producer.produce('ice-cream-melted', { temperature: 35, unit: 'celsius' }, { key: :temperature })
|
45
|
+
|
42
46
|
# This would post a request to the REST Proxy e.g. :
|
43
47
|
# {"id": 1, "temperature": 32, "unit": "celsius"}
|
44
48
|
|
data/kafka_rest_client.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'kafka_rest_client'
|
7
|
-
spec.version = '0.
|
7
|
+
spec.version = '0.4.0'
|
8
8
|
spec.authors = ['Funding Circle Engineering']
|
9
9
|
spec.email = ['engineering+kafka_rest_client@fundingcircle.com']
|
10
10
|
spec.licenses = ['BSD-3-Clause']
|
@@ -83,8 +83,21 @@ module KafkaRestClient
|
|
83
83
|
events.map { |event| annotate_optional_fields(event, optional_fields) }
|
84
84
|
end
|
85
85
|
|
86
|
+
def build_records(events, options)
|
87
|
+
key = options[:key].to_s
|
88
|
+
|
89
|
+
events.map { |event|
|
90
|
+
if key == ""
|
91
|
+
{ value: event }
|
92
|
+
else
|
93
|
+
key_hash = Zlib::crc32(event[key].to_s) # Hacky solution for getting an int hash due to https://github.com/confluentinc/kafka-rest/issues/118
|
94
|
+
{ value: event, key: key_hash }
|
95
|
+
end
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
86
99
|
def build_event_payload(topic, events, options)
|
87
|
-
payload = { records: events
|
100
|
+
payload = { records: build_records(events, options) }.merge(
|
88
101
|
options.select { |k, _| [:value_schema_id, :value_schema].include?(k) }
|
89
102
|
)
|
90
103
|
|
@@ -92,6 +105,10 @@ module KafkaRestClient
|
|
92
105
|
payload[:value_schema_id] = get_latest_schema(topic).fetch('id')
|
93
106
|
end
|
94
107
|
|
108
|
+
if !options[:key].nil?
|
109
|
+
payload[:key_schema] = { type: "long" }.to_json # Should be string, workaround for https://github.com/confluentinc/kafka-rest/issues/118
|
110
|
+
end
|
111
|
+
|
95
112
|
payload
|
96
113
|
end
|
97
114
|
|