kafka_rest_client 0.3.0 → 0.4.0

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: a2547fd6407a534cd9dcc57623b629f2a4dc3f67
4
- data.tar.gz: 46678ca71d81e2ab8d4618c54ef6ae89ac1a912c
3
+ metadata.gz: 0369a154f21c09aa1d3946e42c6ef83835ab3f72
4
+ data.tar.gz: 3b8bdd2fafd712f45754739eb4914f33c5ed9642
5
5
  SHA512:
6
- metadata.gz: ebf98c38adac856ae66952a02081451aebcac5f3406ce157c7656719dd4582ebce5ef39eecc65623b90349c5b92a83f25f92054d14ae32c7c0187c1eb1b87649
7
- data.tar.gz: 69768766374ee6d1d765251888e5c9dae0173470fdccaea8015681768b33743ffd08f3814459ef75d1dc30a9fd5ec22402113a569421b1588470fbb0e30cc309
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.3.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
 
@@ -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.3.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.map { |event| { value: event } } }.merge(
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
 
@@ -15,7 +15,7 @@ module KafkaRestClient
15
15
  @kafka_proxy_url = options[:kafka_proxy_url]
16
16
  @schema_registry_url = options[:schema_registry_url]
17
17
  @timeout = options[:timeout]
18
- @logger = options[:loggger]
18
+ @logger = options[:logger]
19
19
  end
20
20
 
21
21
  def timeout
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kafka_rest_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Funding Circle Engineering