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 +4 -4
- data/README.md +29 -1
- data/lib/pheromone/publishable.rb +5 -4
- data/lib/pheromone/version.rb +1 -1
- 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: b4cb86ee9ef9fea14e1e9993705fd6684472dfd8
|
4
|
+
data.tar.gz: 421982c3b033d1778bcf8e9f4ee7ceec4c039e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
98
|
-
return
|
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
|
data/lib/pheromone/version.rb
CHANGED
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
|
+
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-
|
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
|