artsy-eventservice 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +14 -12
- data/lib/artsy-eventservice/artsy/event_service.rb +8 -1
- data/lib/artsy-eventservice/artsy/event_service/publisher.rb +17 -6
- data/lib/artsy-eventservice/version.rb +1 -1
- data/spec/artsy-eventstream/artsy/event_service_spec.rb +10 -3
- data/spec/artsy-eventstream/artsy/publisher_spec.rb +7 -7
- 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: b78e01513fda0bf9edb4839c1996d5a55c59d422
|
4
|
+
data.tar.gz: 528d6a8bc07e57a6c157d80ea7af6f87ee2dc732
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2df6cb05beab94d16aa9015fcca729fd8d5ce354feeab6ce8e3243dd331adc5d619578267810bf123ebf96a560469072a87bddf41bd5db2ff9580ec72e369f6
|
7
|
+
data.tar.gz: d865174232877df38968b9a963f84d4159dfae91c379b9df87b016e3829369c9d1f639759ffc2e6d9e0c2090d8d895f0981a0e1d6737a0c740a5746df4d5d6fb
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
artsy-eventservice (1.0.
|
4
|
+
artsy-eventservice (1.0.5)
|
5
5
|
bunny (~> 2.7.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -18,8 +18,9 @@ GEM
|
|
18
18
|
diff-lcs (1.2.5)
|
19
19
|
interception (0.5)
|
20
20
|
method_source (0.8.2)
|
21
|
-
|
22
|
-
|
21
|
+
parallel (1.12.1)
|
22
|
+
parser (2.4.0.2)
|
23
|
+
ast (~> 2.3)
|
23
24
|
powerpack (0.1.1)
|
24
25
|
pry (0.10.4)
|
25
26
|
coderay (~> 1.1.0)
|
@@ -33,8 +34,8 @@ GEM
|
|
33
34
|
pry-stack_explorer (0.4.9.2)
|
34
35
|
binding_of_caller (>= 0.7)
|
35
36
|
pry (>= 0.9.11)
|
36
|
-
rainbow (
|
37
|
-
rake (12.
|
37
|
+
rainbow (3.0.0)
|
38
|
+
rake (12.3.0)
|
38
39
|
rspec (3.5.0)
|
39
40
|
rspec-core (~> 3.5.0)
|
40
41
|
rspec-expectations (~> 3.5.0)
|
@@ -48,15 +49,16 @@ GEM
|
|
48
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
50
|
rspec-support (~> 3.5.0)
|
50
51
|
rspec-support (3.5.0)
|
51
|
-
rubocop (0.
|
52
|
-
|
52
|
+
rubocop (0.52.1)
|
53
|
+
parallel (~> 1.10)
|
54
|
+
parser (>= 2.4.0.2, < 3.0)
|
53
55
|
powerpack (~> 0.1)
|
54
|
-
rainbow (>=
|
56
|
+
rainbow (>= 2.2.2, < 4.0)
|
55
57
|
ruby-progressbar (~> 1.7)
|
56
58
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
57
|
-
ruby-progressbar (1.
|
59
|
+
ruby-progressbar (1.9.0)
|
58
60
|
slop (3.6.0)
|
59
|
-
unicode-display_width (1.
|
61
|
+
unicode-display_width (1.3.0)
|
60
62
|
|
61
63
|
PLATFORMS
|
62
64
|
ruby
|
@@ -70,10 +72,10 @@ DEPENDENCIES
|
|
70
72
|
rake
|
71
73
|
rspec
|
72
74
|
rspec-mocks
|
73
|
-
rubocop (~> 0.
|
75
|
+
rubocop (~> 0.48)
|
74
76
|
|
75
77
|
RUBY VERSION
|
76
78
|
ruby 2.3.0p0
|
77
79
|
|
78
80
|
BUNDLED WITH
|
79
|
-
1.
|
81
|
+
1.16.1
|
@@ -2,9 +2,16 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
module Artsy
|
4
4
|
module EventService
|
5
|
+
|
6
|
+
# Post data without an event, data must be a string.
|
7
|
+
def self.post_data(topic:, data:, routing_key: nil)
|
8
|
+
return unless event_stream_enabled?
|
9
|
+
Publisher.publish_data(topic: topic, data: data, routing_key: routing_key)
|
10
|
+
end
|
11
|
+
|
5
12
|
def self.post_event(topic:, event:, routing_key: nil)
|
6
13
|
return unless event_stream_enabled?
|
7
|
-
Publisher.
|
14
|
+
Publisher.publish_event(topic: topic, event: event, routing_key: routing_key || event.routing_key)
|
8
15
|
end
|
9
16
|
|
10
17
|
def self.consume(**args)
|
@@ -2,26 +2,37 @@
|
|
2
2
|
module Artsy
|
3
3
|
module EventService
|
4
4
|
class Publisher
|
5
|
-
def self.
|
5
|
+
def self.publish_event(topic:, event:, routing_key: nil)
|
6
6
|
new.post_event(topic: topic, event: event, routing_key: routing_key)
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def self.publish_data(topic:, data:, routing_key: nil)
|
10
|
+
new.post_data(topic: topic, data: data, routing_key: routing_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
def post_data(topic:, data:, routing_key: nil)
|
11
14
|
RabbitMQConnection.get_channel do |channel|
|
12
15
|
channel.confirm_select if config.confirms_enabled
|
13
16
|
exchange = channel.topic(topic, durable: true)
|
14
17
|
exchange.publish(
|
15
|
-
|
16
|
-
routing_key: routing_key
|
18
|
+
data,
|
19
|
+
routing_key: routing_key,
|
17
20
|
persistent: true,
|
18
21
|
content_type: 'application/json',
|
19
22
|
app_id: config.app_name
|
20
23
|
)
|
21
|
-
raise 'Publishing
|
24
|
+
raise 'Publishing data failed' if config.confirms_enabled && !channel.wait_for_confirms
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
28
|
+
def post_event(topic:, event:, routing_key: nil)
|
29
|
+
raise 'Event missing topic or verb.' if event.verb.to_s.empty? || topic.to_s.empty?
|
30
|
+
post_data(
|
31
|
+
topic: topic,
|
32
|
+
data: event.json,
|
33
|
+
routing_key: routing_key || event.verb)
|
34
|
+
end
|
35
|
+
|
25
36
|
def config
|
26
37
|
Artsy::EventService.config
|
27
38
|
end
|
@@ -21,16 +21,23 @@ describe Artsy::EventService do
|
|
21
21
|
allow(Artsy::EventService).to receive(:config).and_return(double(event_stream_enabled: true))
|
22
22
|
end
|
23
23
|
describe '.post_event' do
|
24
|
-
it 'calls
|
25
|
-
expect(Artsy::EventService::Publisher).to receive(:
|
24
|
+
it 'calls publish_event with proper params' do
|
25
|
+
expect(Artsy::EventService::Publisher).to receive(:publish_event).with(topic: 'test', event: event, routing_key: 'test.passed')
|
26
26
|
|
27
27
|
Artsy::EventService.post_event(topic: 'test', event: event)
|
28
28
|
end
|
29
29
|
it 'calls publish with proper params with routing key' do
|
30
|
-
expect(Artsy::EventService::Publisher).to receive(:
|
30
|
+
expect(Artsy::EventService::Publisher).to receive(:publish_event).with(topic: 'test', event: event, routing_key: 'good.route')
|
31
31
|
|
32
32
|
Artsy::EventService.post_event(topic: 'test', event: event, routing_key: 'good.route')
|
33
33
|
end
|
34
34
|
end
|
35
|
+
describe '.post_data' do
|
36
|
+
it 'calls publish_data with proper params' do
|
37
|
+
expect(Artsy::EventService::Publisher).to receive(:publish_data).with(topic: 'test', data: 'foo', routing_key: 'good.route')
|
38
|
+
|
39
|
+
Artsy::EventService.post_data(topic: 'test', data: 'foo', routing_key: 'good.route')
|
40
|
+
end
|
41
|
+
end
|
35
42
|
end
|
36
43
|
end
|
@@ -19,15 +19,15 @@ describe Artsy::EventService::Publisher do
|
|
19
19
|
|
20
20
|
describe '.publish' do
|
21
21
|
it 'fails when topic is empty' do
|
22
|
-
expect { Artsy::EventService::Publisher.
|
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
|
allow(event).to receive(:verb).and_return('')
|
26
|
-
expect { Artsy::EventService::Publisher.
|
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
|
allow(event).to receive(:verb).and_return(nil)
|
30
|
-
expect { Artsy::EventService::Publisher.
|
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
|
33
33
|
conn = double
|
@@ -48,7 +48,7 @@ describe Artsy::EventService::Publisher do
|
|
48
48
|
content_type: 'application/json',
|
49
49
|
app_id: 'artsy'
|
50
50
|
)
|
51
|
-
Artsy::EventService::Publisher.
|
51
|
+
Artsy::EventService::Publisher.publish_event(topic: 'test', event: event)
|
52
52
|
end
|
53
53
|
it 'uses verb as routing key when calling publish on the exchange without passing routing_key' do
|
54
54
|
conn = double
|
@@ -69,7 +69,7 @@ describe Artsy::EventService::Publisher do
|
|
69
69
|
content_type: 'application/json',
|
70
70
|
app_id: 'artsy'
|
71
71
|
)
|
72
|
-
Artsy::EventService::Publisher.
|
72
|
+
Artsy::EventService::Publisher.publish_event(topic: 'test', event: event, routing_key: 'good.route')
|
73
73
|
end
|
74
74
|
it 'raises an error if event publishing is unconfirmed' do
|
75
75
|
conn = double
|
@@ -91,8 +91,8 @@ describe Artsy::EventService::Publisher do
|
|
91
91
|
app_id: 'artsy'
|
92
92
|
)
|
93
93
|
expect do
|
94
|
-
Artsy::EventService::Publisher.
|
95
|
-
end.to raise_error 'Publishing
|
94
|
+
Artsy::EventService::Publisher.publish_event(topic: 'test', event: event, routing_key: 'good.route')
|
95
|
+
end.to raise_error 'Publishing data failed'
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|