artsy-eventservice 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/artsy-eventservice/artsy/event_service/publisher.rb +4 -4
- data/lib/artsy-eventservice/artsy/event_service.rb +2 -2
- data/lib/artsy-eventservice/version.rb +1 -1
- data/spec/artsy-eventstream/artsy/event_service_spec.rb +7 -2
- data/spec/artsy-eventstream/artsy/publisher_spec.rb +20 -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: 7bcde99f80b60c849663d0402629e335c000669f
|
4
|
+
data.tar.gz: d210c63aee1afc7473c3cd5f42da578368a6756f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 247bdd61719b7885eb5ccd531a4a7747575c983eb482dd88496ced9be9682c517a53fb24181ae18668cbe80639f068d7d30763de7a9bfbb7f3b5c781bfd71179
|
7
|
+
data.tar.gz: 4e8af51716145e1688661e52bcc1c014efc8ebca198a354e6f53632c414a27ea1b5d85e9515a716e9cc21de6d2f5a012a1db029b55f3275fee38588e27ae30ee
|
data/Gemfile.lock
CHANGED
@@ -4,18 +4,18 @@ module Artsy
|
|
4
4
|
class Publisher
|
5
5
|
include RabbitMQConnection
|
6
6
|
|
7
|
-
def self.publish(topic:, event:)
|
8
|
-
new.post_event(topic: topic, event: event)
|
7
|
+
def self.publish(topic:, event:, routing_key: nil)
|
8
|
+
new.post_event(topic: topic, event: event, routing_key: routing_key)
|
9
9
|
end
|
10
10
|
|
11
|
-
def post_event(topic:, event:)
|
11
|
+
def post_event(topic:, event:, routing_key: nil)
|
12
12
|
raise 'Event missing topic or verb.' if event.verb.to_s.empty? || topic.to_s.empty?
|
13
13
|
connect_to_rabbit do |conn|
|
14
14
|
channel = conn.create_channel
|
15
15
|
exchange = channel.topic(topic, durable: true)
|
16
16
|
exchange.publish(
|
17
17
|
event.json,
|
18
|
-
routing_key: event.verb,
|
18
|
+
routing_key: routing_key || event.verb,
|
19
19
|
persistent: true,
|
20
20
|
content_type: 'application/json',
|
21
21
|
app_id: config.app_name
|
@@ -2,9 +2,9 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
module Artsy
|
4
4
|
module EventService
|
5
|
-
def self.post_event(topic:, event:)
|
5
|
+
def self.post_event(topic:, event:, routing_key: nil)
|
6
6
|
return unless event_stream_enabled?
|
7
|
-
Publisher.publish(topic: topic, event: event)
|
7
|
+
Publisher.publish(topic: topic, event: event, routing_key: routing_key)
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.consume(**args)
|
@@ -21,11 +21,16 @@ 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 '
|
25
|
-
expect(Artsy::EventService::Publisher).to receive(:publish)
|
24
|
+
it 'calls publish with proper params' do
|
25
|
+
expect(Artsy::EventService::Publisher).to receive(:publish).with(topic: 'test', event: event, routing_key: nil)
|
26
26
|
|
27
27
|
Artsy::EventService.post_event(topic: 'test', event: event)
|
28
28
|
end
|
29
|
+
it 'calls publish with proper params with routing key' do
|
30
|
+
expect(Artsy::EventService::Publisher).to receive(:publish).with(topic: 'test', event: event, routing_key: 'good.route')
|
31
|
+
|
32
|
+
Artsy::EventService.post_event(topic: 'test', event: event, routing_key: 'good.route')
|
33
|
+
end
|
29
34
|
end
|
30
35
|
end
|
31
36
|
end
|
@@ -29,7 +29,7 @@ describe Artsy::EventService::Publisher do
|
|
29
29
|
allow(event).to receive(:verb).and_return(nil)
|
30
30
|
expect { Artsy::EventService::Publisher.publish(topic: 'test', event: event) }.to raise_error 'Event missing topic or verb.'
|
31
31
|
end
|
32
|
-
it '
|
32
|
+
it 'uses verb as routing key when calling publish on the exchange without passing routing_key' do
|
33
33
|
conn = double
|
34
34
|
channel = double
|
35
35
|
exchange = double
|
@@ -48,5 +48,24 @@ describe Artsy::EventService::Publisher do
|
|
48
48
|
)
|
49
49
|
Artsy::EventService::Publisher.publish(topic: 'test', event: event)
|
50
50
|
end
|
51
|
+
it 'uses verb as routing key when calling publish on the exchange without passing routing_key' do
|
52
|
+
conn = double
|
53
|
+
channel = double
|
54
|
+
exchange = double
|
55
|
+
allow(Bunny).to receive(:new).and_return(conn)
|
56
|
+
expect(conn).to receive(:start).once
|
57
|
+
expect(conn).to receive(:stop).once
|
58
|
+
allow(conn).to receive(:create_channel).and_return(channel)
|
59
|
+
allow(channel).to receive(:topic).with('test', durable: true).and_return(exchange)
|
60
|
+
|
61
|
+
expect(exchange).to receive(:publish).with(
|
62
|
+
JSON.generate(hello: true),
|
63
|
+
routing_key: 'good.route',
|
64
|
+
persistent: true,
|
65
|
+
content_type: 'application/json',
|
66
|
+
app_id: 'artsy'
|
67
|
+
)
|
68
|
+
Artsy::EventService::Publisher.publish(topic: 'test', event: event, routing_key: 'good.route')
|
69
|
+
end
|
51
70
|
end
|
52
71
|
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.2
|
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-07-
|
11
|
+
date: 2017-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|