artsy-eventservice 1.0.2 → 1.0.3

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: 7bcde99f80b60c849663d0402629e335c000669f
4
- data.tar.gz: d210c63aee1afc7473c3cd5f42da578368a6756f
3
+ metadata.gz: b2fc420aec74a16109d3473d71cb71bd2c1fbafd
4
+ data.tar.gz: eda0bb72a66fe5cdc85887ea8d3c0aa325d5bae8
5
5
  SHA512:
6
- metadata.gz: 247bdd61719b7885eb5ccd531a4a7747575c983eb482dd88496ced9be9682c517a53fb24181ae18668cbe80639f068d7d30763de7a9bfbb7f3b5c781bfd71179
7
- data.tar.gz: 4e8af51716145e1688661e52bcc1c014efc8ebca198a354e6f53632c414a27ea1b5d85e9515a716e9cc21de6d2f5a012a1db029b55f3275fee38588e27ae30ee
6
+ metadata.gz: 6bf09515e7ed36508e0f0de94fa652ed91842418b3c79411748c8bf9affc5abad0795d15e2a6aea6b65ee6780e959a586da34d14cad0c4eea486b60fd882ca91
7
+ data.tar.gz: 96323a9511c6db2f81a1f2c5bde6a316b8e9740b43f1385f8698421a2079bbcce5eb73af576871baefcbc654dd534a092f3287be7471bf9e4b722d6e1ac90ce6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artsy-eventservice (1.0.2)
4
+ artsy-eventservice (1.0.3)
5
5
  bunny (~> 2.6.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -59,10 +59,28 @@ Call `post_event` with proper `topic` and `event`:
59
59
  Artsy::EventService.post_event(topic: 'testing', event: event_model)
60
60
  ```
61
61
 
62
+ # How to pick topic and routing key?
63
+ Think of topic as high level business area. From consumer perspective there will be one connection per topic, consumer can decide to filter events they want to receive in that topic based on `routing_key` they listening on. For `topic` use plural names.
64
+
65
+ We recommend to use following `routing_key` strategy:
66
+ `<model_name>.<verb>`.
67
+
68
+ Few examples:
69
+ - Topic: `conversations`, routing key: `message.sent`
70
+ - Topic: `conversations`, routing key: `conversation.created`
71
+ - Topic: `conversations`, routing key: `conversation.dismissed`
72
+ - Topic: `invoices`, routing key: `invoice.paid`
73
+ - Topic: `invoices`, routing key: `merchant_account.created`
74
+
75
+ `BaseEvent` provides `routing_key` method by default which follows the same pattern mention above, you can override `routing_key` when calling `post_event`.
62
76
 
63
77
  ### Update to Version 1.0
64
78
  In previous versions this gem was using Environment variables for configuration. On version 1.0, configuration step is now mandatory and it will no longer read environment variables directly. Make sure to go to configuration step.
65
79
 
80
+ ### Update to Version 1.0.3
81
+ Since this version we've updated `routing_key` to default to `<event object class name>.<event.verb>`. This means if your consumers were listening on `verb` routing key, now they need to update to include object's class name.
82
+ You can always override this feature by passing in `routing_key` to `post_event`.
83
+
66
84
  # Contributing
67
85
 
68
86
  * Fork the project.
@@ -4,7 +4,7 @@ module Artsy
4
4
  module EventService
5
5
  def self.post_event(topic:, event:, routing_key: nil)
6
6
  return unless event_stream_enabled?
7
- Publisher.publish(topic: topic, event: event, routing_key: routing_key)
7
+ Publisher.publish(topic: topic, event: event, routing_key: routing_key || event.routing_key)
8
8
  end
9
9
 
10
10
  def self.consume(**args)
@@ -36,5 +36,9 @@ module Events
36
36
  object: object,
37
37
  properties: properties)
38
38
  end
39
+
40
+ def routing_key
41
+ "#{@object.class.to_s.downcase.gsub('::', '-')}.#{@verb}"
42
+ end
39
43
  end
40
44
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Artsy
3
3
  module EventService
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  end
6
6
  end
@@ -2,7 +2,7 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Artsy::EventService do
5
- let(:event) { double('event', topic: 'foo', verb: 'bar') }
5
+ let(:event) { double('event', topic: 'foo', verb: 'bar', routing_key: 'test.passed') }
6
6
 
7
7
  context 'event stream disabled' do
8
8
  before do
@@ -22,7 +22,7 @@ describe Artsy::EventService do
22
22
  end
23
23
  describe '.post_event' do
24
24
  it 'calls publish with proper params' do
25
- expect(Artsy::EventService::Publisher).to receive(:publish).with(topic: 'test', event: event, routing_key: nil)
25
+ expect(Artsy::EventService::Publisher).to receive(:publish).with(topic: 'test', event: event, routing_key: 'test.passed')
26
26
 
27
27
  Artsy::EventService.post_event(topic: 'test', event: event)
28
28
  end
@@ -32,4 +32,9 @@ describe Events::BaseEvent do
32
32
  )
33
33
  end
34
34
  end
35
+ describe '#routing_key' do
36
+ it 'returns proper routing key' do
37
+ expect(event.routing_key).to eq 'rspec-mocks-double.test'
38
+ end
39
+ end
35
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artsy-eventservice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashkan Nasseri