artsy-eventservice 1.0.6 → 1.0.8
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/Gemfile.lock +1 -1
- data/lib/artsy-eventservice/artsy/event_service/publisher.rb +10 -7
- data/lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb +2 -0
- data/lib/artsy-eventservice/version.rb +1 -1
- data/spec/artsy-eventstream/artsy/event_service/rabbitmq_connection_spec.rb +33 -0
- data/spec/artsy-eventstream/artsy/publisher_spec.rb +47 -22
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b57886405d5d5d74bc384e16ad8ba63229665cb9
|
4
|
+
data.tar.gz: 3735eb18d6c4ceb84ce01c81902673031d2931bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e39e3b5ada09e10aa556b087c56ba20cfa1f6f6f263e4a8c9f9eb096cf1114f0d2b489c0eda41c45b88e5518c437d59650d9a14f509697ee784a3b8a1afe1c93
|
7
|
+
data.tar.gz: 0f6b44839fb093d5094c2236c5d7efdad0344a2a9490df774a9b4661823004baf1504c1052e405b9b077cefe768c614ee6b307725aeb21b29f061af80b912c94
|
data/Gemfile.lock
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
module Artsy
|
3
3
|
module EventService
|
4
4
|
class Publisher
|
5
|
-
def self.publish_event(topic:, event:, routing_key: nil)
|
6
|
-
new.post_event(topic: topic, event: event, routing_key: routing_key)
|
5
|
+
def self.publish_event(topic:, event:, routing_key: nil, headers: {})
|
6
|
+
new.post_event(topic: topic, event: event, routing_key: routing_key, headers: headers)
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.publish_data(topic:, data:, routing_key: nil)
|
10
|
-
new.post_data(topic: topic, data: data, routing_key: routing_key)
|
9
|
+
def self.publish_data(topic:, data:, routing_key: nil, headers: {})
|
10
|
+
new.post_data(topic: topic, data: data, routing_key: routing_key, headers: headers)
|
11
11
|
end
|
12
12
|
|
13
|
-
def post_data(topic:, data:, routing_key: nil)
|
13
|
+
def post_data(topic:, data:, routing_key: nil, headers: {})
|
14
14
|
RabbitMQConnection.get_channel do |channel|
|
15
15
|
channel.confirm_select if config.confirms_enabled
|
16
16
|
exchange = channel.topic(topic, durable: true)
|
@@ -19,18 +19,21 @@ module Artsy
|
|
19
19
|
routing_key: routing_key,
|
20
20
|
persistent: true,
|
21
21
|
content_type: 'application/json',
|
22
|
+
headers: headers,
|
22
23
|
app_id: config.app_name
|
23
24
|
)
|
24
25
|
raise 'Publishing data failed' if config.confirms_enabled && !channel.wait_for_confirms
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
def post_event(topic:, event:, routing_key: nil)
|
29
|
+
def post_event(topic:, event:, routing_key: nil, headers: {})
|
29
30
|
raise 'Event missing topic or verb.' if event.verb.to_s.empty? || topic.to_s.empty?
|
30
31
|
post_data(
|
31
32
|
topic: topic,
|
32
33
|
data: event.json,
|
33
|
-
routing_key: routing_key || event.verb
|
34
|
+
routing_key: routing_key || event.verb,
|
35
|
+
headers: headers
|
36
|
+
)
|
34
37
|
end
|
35
38
|
|
36
39
|
def config
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Artsy::EventService::RabbitMQConnection do
|
5
|
+
describe '.get_connection' do
|
6
|
+
before :each do
|
7
|
+
Artsy::EventService::RabbitMQConnection.instance_variable_set(:@connection, nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'with an open connection' do
|
11
|
+
it 'returns that connection' do
|
12
|
+
open_conn = double(:open_conn, closed?: false, start: nil)
|
13
|
+
expect(Bunny).to receive(:new).once.and_return(open_conn)
|
14
|
+
|
15
|
+
connection = Artsy::EventService::RabbitMQConnection.get_connection
|
16
|
+
|
17
|
+
expect(connection).to eq open_conn
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with a closed connection' do
|
22
|
+
it 'rebuilds and returns that new connection' do
|
23
|
+
closed_conn = double(:closed_conn, closed?: true, start: nil)
|
24
|
+
open_conn = double(:open_conn, closed?: false, start: nil)
|
25
|
+
expect(Bunny).to receive(:new).twice.and_return(closed_conn, open_conn)
|
26
|
+
|
27
|
+
connection = Artsy::EventService::RabbitMQConnection.get_connection
|
28
|
+
|
29
|
+
expect(connection).to eq open_conn
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -22,11 +22,11 @@ describe Artsy::EventService::Publisher do
|
|
22
22
|
expect { Artsy::EventService::Publisher.publish_event(topic: nil, event: event) }.to raise_error 'Event missing topic or verb.'
|
23
23
|
end
|
24
24
|
it 'fails when event.verb is empty' do
|
25
|
-
|
25
|
+
expect(event).to receive(:verb).and_return('')
|
26
26
|
expect { Artsy::EventService::Publisher.publish_event(topic: 'test', event: event) }.to raise_error 'Event missing topic or verb.'
|
27
27
|
end
|
28
28
|
it 'fails when event.verb is nil' do
|
29
|
-
|
29
|
+
expect(event).to receive(:verb).and_return(nil)
|
30
30
|
expect { Artsy::EventService::Publisher.publish_event(topic: 'test', event: event) }.to raise_error 'Event missing topic or verb.'
|
31
31
|
end
|
32
32
|
it 'uses verb as routing key when calling publish on the exchange without passing routing_key' do
|
@@ -34,60 +34,85 @@ describe Artsy::EventService::Publisher do
|
|
34
34
|
channel = double
|
35
35
|
exchange = double
|
36
36
|
allow(Artsy::EventService::RabbitMQConnection).to receive(:get_connection).with(no_args).and_return(conn)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
expect(conn).to receive(:create_channel).and_return(channel)
|
38
|
+
expect(channel).to receive(:open?).and_return(true)
|
39
|
+
expect(channel).to receive(:topic).with('test', durable: true).and_return(exchange)
|
40
|
+
expect(channel).to receive(:confirm_select)
|
41
|
+
expect(channel).to receive(:wait_for_confirms).and_return(true)
|
42
|
+
expect(channel).to receive(:close)
|
43
43
|
|
44
44
|
expect(exchange).to receive(:publish).with(
|
45
45
|
JSON.generate(hello: true),
|
46
46
|
routing_key: 'testing',
|
47
47
|
persistent: true,
|
48
48
|
content_type: 'application/json',
|
49
|
+
headers: {},
|
49
50
|
app_id: 'artsy'
|
50
51
|
)
|
51
52
|
Artsy::EventService::Publisher.publish_event(topic: 'test', event: event)
|
52
53
|
end
|
53
|
-
it 'uses
|
54
|
+
it 'uses the provided routing_key key when calling publish on the exchange when passing routing_key' do
|
54
55
|
conn = double
|
55
56
|
channel = double
|
56
57
|
exchange = double
|
57
58
|
allow(Artsy::EventService::RabbitMQConnection).to receive(:get_connection).with(no_args).and_return(conn)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
expect(conn).to receive(:create_channel).and_return(channel)
|
60
|
+
expect(channel).to receive(:open?).and_return(true)
|
61
|
+
expect(channel).to receive(:topic).with('test', durable: true).and_return(exchange)
|
62
|
+
expect(channel).to receive(:confirm_select)
|
63
|
+
expect(channel).to receive(:wait_for_confirms).and_return(true)
|
64
|
+
expect(channel).to receive(:close)
|
64
65
|
|
65
66
|
expect(exchange).to receive(:publish).with(
|
66
67
|
JSON.generate(hello: true),
|
67
68
|
routing_key: 'good.route',
|
68
69
|
persistent: true,
|
69
70
|
content_type: 'application/json',
|
71
|
+
headers: {},
|
70
72
|
app_id: 'artsy'
|
71
73
|
)
|
72
74
|
Artsy::EventService::Publisher.publish_event(topic: 'test', event: event, routing_key: 'good.route')
|
73
75
|
end
|
74
|
-
it '
|
76
|
+
it 'passes through provided headers when calling publish on the exchange' do
|
75
77
|
conn = double
|
76
78
|
channel = double
|
77
79
|
exchange = double
|
78
80
|
allow(Artsy::EventService::RabbitMQConnection).to receive(:get_connection).with(no_args).and_return(conn)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
expect(conn).to receive(:create_channel).and_return(channel)
|
82
|
+
expect(channel).to receive(:open?).and_return(true)
|
83
|
+
expect(channel).to receive(:topic).with('test', durable: true).and_return(exchange)
|
84
|
+
expect(channel).to receive(:confirm_select)
|
85
|
+
expect(channel).to receive(:wait_for_confirms).and_return(true)
|
86
|
+
expect(channel).to receive(:close)
|
87
|
+
|
88
|
+
expect(exchange).to receive(:publish).with(
|
89
|
+
JSON.generate(hello: true),
|
90
|
+
routing_key: 'good.route',
|
91
|
+
persistent: true,
|
92
|
+
content_type: 'application/json',
|
93
|
+
headers: {"x-foo": "bar"},
|
94
|
+
app_id: 'artsy'
|
95
|
+
)
|
96
|
+
Artsy::EventService::Publisher.publish_event(topic: 'test', event: event, routing_key: 'good.route', headers: {"x-foo": "bar"})
|
97
|
+
end
|
98
|
+
it 'raises an error if event publishing is unconfirmed' do
|
99
|
+
conn = double
|
100
|
+
channel = double
|
101
|
+
exchange = double
|
102
|
+
expect(Artsy::EventService::RabbitMQConnection).to receive(:get_connection).with(no_args).and_return(conn)
|
103
|
+
expect(conn).to receive(:create_channel).and_return(channel)
|
104
|
+
expect(channel).to receive(:open?).and_return(true)
|
105
|
+
expect(channel).to receive(:topic).with('test', durable: true).and_return(exchange)
|
106
|
+
expect(channel).to receive(:confirm_select)
|
107
|
+
expect(channel).to receive(:wait_for_confirms).and_return(false)
|
108
|
+
expect(channel).to receive(:close)
|
85
109
|
|
86
110
|
expect(exchange).to receive(:publish).with(
|
87
111
|
JSON.generate(hello: true),
|
88
112
|
routing_key: 'good.route',
|
89
113
|
persistent: true,
|
90
114
|
content_type: 'application/json',
|
115
|
+
headers: {},
|
91
116
|
app_id: 'artsy'
|
92
117
|
)
|
93
118
|
expect do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artsy-eventservice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/artsy-eventservice/config.rb
|
51
51
|
- lib/artsy-eventservice/presenters/events/base_event.rb
|
52
52
|
- lib/artsy-eventservice/version.rb
|
53
|
+
- spec/artsy-eventstream/artsy/event_service/rabbitmq_connection_spec.rb
|
53
54
|
- spec/artsy-eventstream/artsy/event_service_spec.rb
|
54
55
|
- spec/artsy-eventstream/artsy/publisher_spec.rb
|
55
56
|
- spec/artsy-eventstream/config_spec.rb
|
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
77
|
version: 1.3.6
|
77
78
|
requirements: []
|
78
79
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
80
|
+
rubygems_version: 2.4.8
|
80
81
|
signing_key:
|
81
82
|
specification_version: 4
|
82
83
|
summary: Ruby Gem for producing events in Artsy's event stream
|