artsy-eventservice 1.0.3 → 1.0.4
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 +6 -6
- data/artsy-eventservice.gemspec +1 -1
- data/lib/artsy-eventservice/artsy/event_service/publisher.rb +4 -5
- data/lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb +34 -22
- data/lib/artsy-eventservice/config.rb +2 -0
- data/lib/artsy-eventservice/version.rb +1 -1
- data/spec/artsy-eventstream/artsy/publisher_spec.rb +33 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 730a1c3e93fc39daa432c14e98e4d3e470bd21d5
|
4
|
+
data.tar.gz: b91155920aa1d4d24d9c1c96e1b13cb822a121ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26960c9c97661ea5bba215c7863f78162713e975ea60917527d0d6a3ba8fb6809a94ce1d34c7f9f2e6770aa07e628a4f950aacffd7cd089f3e7364b61eddc726
|
7
|
+
data.tar.gz: e4a4eddb337a77cba72ed97d39c9f06225ea42c40ffa34e92ffd6dc0d417a60582e7135387b9e2a04633aee652241a30f5c578bd48388b3f2121dd2bb730f29e
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
artsy-eventservice (1.0.
|
5
|
-
bunny (~> 2.
|
4
|
+
artsy-eventservice (1.0.4)
|
5
|
+
bunny (~> 2.7.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
amq-protocol (2.0
|
10
|
+
amq-protocol (2.2.0)
|
11
11
|
ast (2.3.0)
|
12
12
|
binding_of_caller (0.7.2)
|
13
13
|
debug_inspector (>= 0.0.1)
|
14
|
-
bunny (2.
|
15
|
-
amq-protocol (>= 2.0
|
14
|
+
bunny (2.7.1)
|
15
|
+
amq-protocol (>= 2.2.0)
|
16
16
|
coderay (1.1.1)
|
17
17
|
debug_inspector (0.0.2)
|
18
18
|
diff-lcs (1.2.5)
|
@@ -76,4 +76,4 @@ RUBY VERSION
|
|
76
76
|
ruby 2.3.0p0
|
77
77
|
|
78
78
|
BUNDLED WITH
|
79
|
-
1.
|
79
|
+
1.15.4
|
data/artsy-eventservice.gemspec
CHANGED
@@ -15,5 +15,5 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.homepage = 'http://github.com/artsy/artsy-eventservice'
|
16
16
|
s.licenses = ['MIT']
|
17
17
|
s.summary = "Ruby Gem for producing events in Artsy's event stream"
|
18
|
-
s.add_dependency 'bunny', '~> 2.
|
18
|
+
s.add_dependency 'bunny', '~> 2.7.1'
|
19
19
|
end
|
@@ -2,16 +2,14 @@
|
|
2
2
|
module Artsy
|
3
3
|
module EventService
|
4
4
|
class Publisher
|
5
|
-
include RabbitMQConnection
|
6
|
-
|
7
5
|
def self.publish(topic:, event:, routing_key: nil)
|
8
6
|
new.post_event(topic: topic, event: event, routing_key: routing_key)
|
9
7
|
end
|
10
8
|
|
11
9
|
def post_event(topic:, event:, routing_key: nil)
|
12
10
|
raise 'Event missing topic or verb.' if event.verb.to_s.empty? || topic.to_s.empty?
|
13
|
-
|
14
|
-
channel
|
11
|
+
RabbitMQConnection.get_channel do |channel|
|
12
|
+
channel.confirm_select if config.confirms_enabled
|
15
13
|
exchange = channel.topic(topic, durable: true)
|
16
14
|
exchange.publish(
|
17
15
|
event.json,
|
@@ -20,10 +18,11 @@ module Artsy
|
|
20
18
|
content_type: 'application/json',
|
21
19
|
app_id: config.app_name
|
22
20
|
)
|
21
|
+
raise 'Publishing event failed' if config.confirms_enabled && !channel.wait_for_confirms
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
25
|
+
def config
|
27
26
|
Artsy::EventService.config
|
28
27
|
end
|
29
28
|
end
|
@@ -3,43 +3,55 @@ require 'bunny'
|
|
3
3
|
|
4
4
|
module Artsy
|
5
5
|
module EventService
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Bunny.new(rabbitmq_url, **bunny_params)
|
10
|
-
end
|
6
|
+
class RabbitMQConnection
|
7
|
+
@connection = nil
|
8
|
+
@mutex = Mutex.new
|
11
9
|
|
12
|
-
#
|
13
|
-
def
|
14
|
-
conn =
|
10
|
+
# Build a new connection to RabbitMQ
|
11
|
+
def self.build_connection
|
12
|
+
conn = Bunny.new(self.rabbitmq_url, **self.bunny_params)
|
15
13
|
conn.start
|
16
|
-
|
17
|
-
|
14
|
+
conn
|
15
|
+
end
|
16
|
+
|
17
|
+
# Synchronized access to the connection
|
18
|
+
def self.get_connection
|
19
|
+
@mutex.synchronize do
|
20
|
+
@connection ||= self.build_connection
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get a channel from the connection - synchronized access to create_channel is provided by Bunny
|
25
|
+
def self.get_channel
|
26
|
+
channel = self.get_connection.create_channel
|
27
|
+
yield channel if block_given?
|
28
|
+
ensure
|
29
|
+
channel.close if channel && channel.open?
|
18
30
|
end
|
19
31
|
|
20
|
-
def rabbitmq_url
|
21
|
-
config.rabbitmq_url
|
32
|
+
def self.rabbitmq_url
|
33
|
+
self.config.rabbitmq_url
|
22
34
|
end
|
23
35
|
|
24
|
-
def bunny_params
|
25
|
-
config.tls ? tls_params : no_tls_params
|
36
|
+
def self.bunny_params
|
37
|
+
self.config.tls ? self.tls_params : self.no_tls_params
|
26
38
|
end
|
27
39
|
|
28
|
-
def tls_params
|
40
|
+
def self.tls_params
|
29
41
|
{
|
30
|
-
tls: config.tls,
|
31
|
-
tls_cert: config.tls_cert,
|
32
|
-
tls_key: config.tls_key,
|
33
|
-
tls_ca_certificates: [config.tls_ca_certificate],
|
34
|
-
verify_peer: config.verify_peer
|
42
|
+
tls: self.config.tls,
|
43
|
+
tls_cert: self.config.tls_cert,
|
44
|
+
tls_key: self.config.tls_key,
|
45
|
+
tls_ca_certificates: [self.config.tls_ca_certificate],
|
46
|
+
verify_peer: self.config.verify_peer
|
35
47
|
}
|
36
48
|
end
|
37
49
|
|
38
|
-
def no_tls_params
|
50
|
+
def self.no_tls_params
|
39
51
|
{}
|
40
52
|
end
|
41
53
|
|
42
|
-
def config
|
54
|
+
def self.config
|
43
55
|
Artsy::EventService.config
|
44
56
|
end
|
45
57
|
end
|
@@ -13,6 +13,7 @@ module Artsy
|
|
13
13
|
attr_accessor :tls_cert
|
14
14
|
attr_accessor :tls_key
|
15
15
|
attr_accessor :verify_peer
|
16
|
+
attr_accessor :confirms_enabled
|
16
17
|
|
17
18
|
def reset
|
18
19
|
self.app_name = nil
|
@@ -23,6 +24,7 @@ module Artsy
|
|
23
24
|
self.tls_cert = nil
|
24
25
|
self.tls_key = nil
|
25
26
|
self.verify_peer = nil
|
27
|
+
self.confirms_enabled = true
|
26
28
|
end
|
27
29
|
|
28
30
|
reset
|
@@ -33,11 +33,13 @@ describe Artsy::EventService::Publisher do
|
|
33
33
|
conn = double
|
34
34
|
channel = double
|
35
35
|
exchange = double
|
36
|
-
allow(
|
37
|
-
expect(conn).to receive(:start).once
|
38
|
-
expect(conn).to receive(:stop).once
|
36
|
+
allow(Artsy::EventService::RabbitMQConnection).to receive(:get_connection).with(no_args).and_return(conn)
|
39
37
|
allow(conn).to receive(:create_channel).and_return(channel)
|
38
|
+
allow(channel).to receive(:open?).and_return(true)
|
40
39
|
allow(channel).to receive(:topic).with('test', durable: true).and_return(exchange)
|
40
|
+
allow(channel).to receive(:confirm_select)
|
41
|
+
allow(channel).to receive(:wait_for_confirms).and_return(true)
|
42
|
+
allow(channel).to receive(:close)
|
41
43
|
|
42
44
|
expect(exchange).to receive(:publish).with(
|
43
45
|
JSON.generate(hello: true),
|
@@ -52,11 +54,13 @@ describe Artsy::EventService::Publisher do
|
|
52
54
|
conn = double
|
53
55
|
channel = double
|
54
56
|
exchange = double
|
55
|
-
allow(
|
56
|
-
expect(conn).to receive(:start).once
|
57
|
-
expect(conn).to receive(:stop).once
|
57
|
+
allow(Artsy::EventService::RabbitMQConnection).to receive(:get_connection).with(no_args).and_return(conn)
|
58
58
|
allow(conn).to receive(:create_channel).and_return(channel)
|
59
|
+
allow(channel).to receive(:open?).and_return(true)
|
59
60
|
allow(channel).to receive(:topic).with('test', durable: true).and_return(exchange)
|
61
|
+
allow(channel).to receive(:confirm_select)
|
62
|
+
allow(channel).to receive(:wait_for_confirms).and_return(true)
|
63
|
+
allow(channel).to receive(:close)
|
60
64
|
|
61
65
|
expect(exchange).to receive(:publish).with(
|
62
66
|
JSON.generate(hello: true),
|
@@ -67,5 +71,28 @@ describe Artsy::EventService::Publisher do
|
|
67
71
|
)
|
68
72
|
Artsy::EventService::Publisher.publish(topic: 'test', event: event, routing_key: 'good.route')
|
69
73
|
end
|
74
|
+
it 'raises an error if event publishing is unconfirmed' do
|
75
|
+
conn = double
|
76
|
+
channel = double
|
77
|
+
exchange = double
|
78
|
+
allow(Artsy::EventService::RabbitMQConnection).to receive(:get_connection).with(no_args).and_return(conn)
|
79
|
+
allow(conn).to receive(:create_channel).and_return(channel)
|
80
|
+
allow(channel).to receive(:open?).and_return(true)
|
81
|
+
allow(channel).to receive(:topic).with('test', durable: true).and_return(exchange)
|
82
|
+
allow(channel).to receive(:confirm_select)
|
83
|
+
allow(channel).to receive(:wait_for_confirms).and_return(false)
|
84
|
+
allow(channel).to receive(:close)
|
85
|
+
|
86
|
+
expect(exchange).to receive(:publish).with(
|
87
|
+
JSON.generate(hello: true),
|
88
|
+
routing_key: 'good.route',
|
89
|
+
persistent: true,
|
90
|
+
content_type: 'application/json',
|
91
|
+
app_id: 'artsy'
|
92
|
+
)
|
93
|
+
expect do
|
94
|
+
Artsy::EventService::Publisher.publish(topic: 'test', event: event, routing_key: 'good.route')
|
95
|
+
end.to raise_error 'Publishing event failed'
|
96
|
+
end
|
70
97
|
end
|
71
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.7.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.7.1
|
27
27
|
description:
|
28
28
|
email: ashkan.nasseri@gmail.com
|
29
29
|
executables: []
|