pheromone 0.4.4 → 0.4.5

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: a76799fc95a8238c6a7fddcc083aae52611f46a1
4
- data.tar.gz: 61f88eb5864f2afb37daa82cda0b3212a787cff8
3
+ metadata.gz: b4cb86ee9ef9fea14e1e9993705fd6684472dfd8
4
+ data.tar.gz: 421982c3b033d1778bcf8e9f4ee7ceec4c039e18
5
5
  SHA512:
6
- metadata.gz: ce43f010d7559642d2707433d0e271c3eabea9c3f5aa960f5a247a9f621b9be890b6ab972150a2b305b9afaaaed9a8e36c6f0153620ff79e8d42e96ec7481e86
7
- data.tar.gz: aeefa586c94343abfc1957f1033ba619d4fb2f85ac3998a9850f50a6c6dc4940ea76fe1b7adf592a6f1f956368d3df047fe8528a46dfec26d0f516701a0710a1
6
+ metadata.gz: 192c520604afdabf44a96ab535ce14f3c2a7408d9684670a2986a9d7dfbac8f1e6cfe937a45b8a14c6502a5597a907117b58892f499f44e5855b9a6418fb3f84
7
+ data.tar.gz: e3c87d8c40b5475097c05eeba2fe19348d16a83a50e17aef41c2e27d3be309eee090b517b2c9e938a44f965ab630c8a61e8f8b628942f76ad5c6f22a722fa931
data/README.md CHANGED
@@ -58,6 +58,7 @@ The timezone setting will transform any timestamp attributes in the message to t
58
58
 
59
59
  ## Usage
60
60
 
61
+
61
62
  ### 1. Sending messages to kafka asynchronously
62
63
 
63
64
  The underlying Kafka client used by `pheromone` is `ruby-kafka`. This client provides a normal producer that sends messages to Kafka synchronously, and an `async_producer` to send messages to Kafka asynchronously.
@@ -297,7 +298,20 @@ end
297
298
 
298
299
  ### 7. Specifying message metadata
299
300
 
300
- These can be sent in by specifying `metadata` to the `publish` method:
301
+ Pheromone makes it easier to standardise the format of messages sent to Kafka while affording the flexibility to add other custom fields using the metadata option.
302
+
303
+ By default, the messages sent to Kafka have an event_type and timestamp attached to it as shown below:
304
+ ```
305
+ {
306
+ 'event_type' => 'create',
307
+ 'timestamp' => '2015-07-14T10:10:00.000+08:00',
308
+ 'blob' => {
309
+ 'message_text' => 'test'
310
+ }
311
+ }.to_json
312
+ ```
313
+
314
+ By specifying `metadata` to the `publish` method:
301
315
 
302
316
  ```
303
317
  class PublishableModel < ActiveRecord::Base
@@ -318,6 +332,20 @@ class PublishableModel < ActiveRecord::Base
318
332
  end
319
333
  ```
320
334
 
335
+ The Kafka message will have the original metadata in addition to the new fields:
336
+
337
+
338
+ ```
339
+ {
340
+ 'event_type' => 'create',
341
+ 'timestamp' => '2015-07-14T10:10:00.000+08:00',
342
+ 'source' => 'application1',
343
+ 'blob' => {
344
+ 'message_text' => 'test'
345
+ }
346
+ }.to_json
347
+ ```
348
+
321
349
  ### 8. Sending messages to Kafka directly
322
350
 
323
351
  `pheromone` provides a custom message object that sends messages to Kafka in a predefined format, to maintain consistency in the message fields.
@@ -94,9 +94,10 @@ module Pheromone
94
94
 
95
95
  def message_meta_data(options, current_event)
96
96
  metadata = options[:metadata]
97
- return { event: current_event, entity: self.class.name } if metadata.blank?
98
- return metadata if metadata.is_a?(Hash)
99
- call_proc_or_instance_method(metadata)
97
+ default_metadata = { event: current_event, entity: self.class.name }
98
+ return default_metadata if metadata.blank?
99
+ provided_metadata = metadata.is_a?(Hash) ? metadata : call_proc_or_instance_method(metadata)
100
+ default_metadata.merge!(provided_metadata)
100
101
  end
101
102
 
102
103
  def message_blob(options)
@@ -111,4 +112,4 @@ module Pheromone
111
112
  base.send :extend, ClassMethods
112
113
  end
113
114
  end
114
- end
115
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Pheromone
3
- VERSION = '0.4.4'.freeze
3
+ VERSION = '0.4.5'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pheromone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankita Gupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-10 00:00:00.000000000 Z
11
+ date: 2018-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers