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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a7279cae09152a9ac7a1ddace21b41204107959
4
- data.tar.gz: 408d96afb3aed0492a616081d4e4697350216eb4
3
+ metadata.gz: 7bcde99f80b60c849663d0402629e335c000669f
4
+ data.tar.gz: d210c63aee1afc7473c3cd5f42da578368a6756f
5
5
  SHA512:
6
- metadata.gz: 651025fc9da750f6b073566313bd669d032b3abce49fa6f8dcb2cf56d3084ab8bc22b57c7320d98479c82e12cca9ef08f398e3b56b6dffe8ea5f69763de0506e
7
- data.tar.gz: 73eac6af6005a8a23b4810ed7daa675125332b07754928b6d83650a7d5bc92765ca9c3496ebe2f8e1a360ed9a8265bb6805f077b506d74e7b2c99d0b5b189a14
6
+ metadata.gz: 247bdd61719b7885eb5ccd531a4a7747575c983eb482dd88496ced9be9682c517a53fb24181ae18668cbe80639f068d7d30763de7a9bfbb7f3b5c781bfd71179
7
+ data.tar.gz: 4e8af51716145e1688661e52bcc1c014efc8ebca198a354e6f53632c414a27ea1b5d85e9515a716e9cc21de6d2f5a012a1db029b55f3275fee38588e27ae30ee
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artsy-eventservice (1.0.1)
4
+ artsy-eventservice (1.0.2)
5
5
  bunny (~> 2.6.2)
6
6
 
7
7
  GEM
@@ -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)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Artsy
3
3
  module EventService
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
6
6
  end
@@ -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 'does connect to rabbit' do
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 'calls publish on the exchange with proper data' do
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.1
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-12 00:00:00.000000000 Z
11
+ date: 2017-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny