philotic 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/philotic.rb +8 -4
- data/lib/philotic/config.rb +30 -29
- data/lib/philotic/connection.rb +2 -0
- data/lib/philotic/version.rb +1 -1
- data/spec/philotic/connection_spec.rb +12 -3
- data/spec/philotic/publisher_spec.rb +39 -33
- data/spec/philotic_spec.rb +10 -8
- data/spec/spec_helper.rb +0 -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: 47b970f227032a30e680562ee09c41d2ba6f5a46
|
4
|
+
data.tar.gz: bbc36d33ee8bdd0c09b7b9a2af4a0b3dfe991f5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a368f139afcdfa7e9516653cd8f9455ec7d6b24bc33eef603b129a5366f25b2e1fb9ac52f70d85dadbc35995b4b201678ba22046edc4da32cbf98aa5b9f97e08
|
7
|
+
data.tar.gz: ff47fae4fb59c8e39c4fe73974295780765e6239e7c9d6f25e2c6a296ea2149add58f8d628ce9eff0d207d0068899686e0a307983db0c1e52ba569720d95f958
|
data/.travis.yml
CHANGED
data/lib/philotic.rb
CHANGED
@@ -21,13 +21,13 @@ module Philotic
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.initialize_named_queue!(queue_name, config)
|
24
|
-
raise
|
24
|
+
raise 'Philotic::Config.initialize_named_queues must be true to run Philotic.initialize_named_queue!' unless Philotic::Config.initialize_named_queues
|
25
25
|
|
26
26
|
Philotic.connect!
|
27
27
|
queue_exists = Philotic::Connection.connection.queue_exists? queue_name
|
28
28
|
|
29
|
-
should_delete_queue = queue_exists &&
|
30
|
-
should_create_queue = !queue_exists ||
|
29
|
+
should_delete_queue = queue_exists && Philotic::Config.delete_existing_queues
|
30
|
+
should_create_queue = !queue_exists || Philotic::Config.delete_existing_queues
|
31
31
|
|
32
32
|
if should_delete_queue
|
33
33
|
Philotic::Connection.channel.queue(queue_name, passive: true).delete
|
@@ -39,7 +39,7 @@ module Philotic
|
|
39
39
|
queue = queue_from_config(queue_name, config)
|
40
40
|
bind_queue(queue, config)
|
41
41
|
else
|
42
|
-
Philotic.logger.warn "Queue #{queue_name} not created; it already exists.
|
42
|
+
Philotic.logger.warn "Queue #{queue_name} not created; it already exists. Philotic::Config.delete_existing_queues must be true to override."
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -94,6 +94,10 @@ module Philotic
|
|
94
94
|
def self.connect!
|
95
95
|
Philotic::Connection.connect!
|
96
96
|
end
|
97
|
+
|
98
|
+
def self.close
|
99
|
+
Philotic::Connection.close
|
100
|
+
end
|
97
101
|
end
|
98
102
|
|
99
103
|
require 'philotic/version'
|
data/lib/philotic/config.rb
CHANGED
@@ -11,41 +11,42 @@ module Philotic
|
|
11
11
|
|
12
12
|
ENV_PREFIX = 'PHILOTIC'
|
13
13
|
|
14
|
-
DEFAULT_DISABLE_PUBLISH
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
DEFAULT_DISABLE_PUBLISH = false
|
15
|
+
DEFAULT_INITIALIZE_NAMED_QUEUES = false
|
16
|
+
DEFAULT_DELETE_EXISTING_QUEUES = false
|
17
|
+
DEFAULT_RABBIT_SCHEME = 'amqps'
|
18
|
+
DEFAULT_RABBIT_HOST = 'localhost'
|
19
|
+
DEFAULT_RABBIT_PORT = 5671
|
20
|
+
DEFAULT_RABBIT_USER = 'guest'
|
21
|
+
DEFAULT_RABBIT_PASSWORD = 'guest'
|
22
|
+
DEFAULT_RABBIT_VHOST = '%2f' # '/'
|
23
|
+
DEFAULT_RABBIT_URL = "#{DEFAULT_RABBIT_SCHEME}://#{DEFAULT_RABBIT_USER}:#{DEFAULT_RABBIT_PASSWORD}@#{DEFAULT_RABBIT_HOST}:#{DEFAULT_RABBIT_PORT}/#{DEFAULT_RABBIT_VHOST}"
|
24
|
+
DEFAULT_EXCHANGE_NAME = 'philotic.headers'
|
25
|
+
DEFAULT_TIMEOUT = 2
|
26
|
+
DEFAULT_ROUTING_KEY = nil
|
27
|
+
DEFAULT_PERSISTENT = true
|
27
28
|
# DEFAULT_IMMEDIATE = false
|
28
|
-
DEFAULT_MANDATORY
|
29
|
-
DEFAULT_CONTENT_TYPE
|
30
|
-
DEFAULT_CONTENT_ENCODING
|
31
|
-
DEFAULT_PRIORITY
|
32
|
-
DEFAULT_MESSAGE_ID
|
33
|
-
DEFAULT_CORRELATION_ID
|
34
|
-
DEFAULT_REPLY_TO
|
35
|
-
DEFAULT_TYPE
|
36
|
-
DEFAULT_USER_ID
|
37
|
-
DEFAULT_APP_ID
|
38
|
-
DEFAULT_TIMESTAMP
|
39
|
-
DEFAULT_EXPIRATION
|
29
|
+
DEFAULT_MANDATORY = true
|
30
|
+
DEFAULT_CONTENT_TYPE = nil
|
31
|
+
DEFAULT_CONTENT_ENCODING = nil
|
32
|
+
DEFAULT_PRIORITY = nil
|
33
|
+
DEFAULT_MESSAGE_ID = nil
|
34
|
+
DEFAULT_CORRELATION_ID = nil
|
35
|
+
DEFAULT_REPLY_TO = nil
|
36
|
+
DEFAULT_TYPE = nil
|
37
|
+
DEFAULT_USER_ID = nil
|
38
|
+
DEFAULT_APP_ID = nil
|
39
|
+
DEFAULT_TIMESTAMP = nil
|
40
|
+
DEFAULT_EXPIRATION = nil
|
40
41
|
|
41
42
|
def defaults
|
42
43
|
@defaults ||= Hash[Config.constants.select { |c| c.to_s.start_with? 'DEFAULT_' }.collect do |c|
|
43
|
-
|
44
|
+
key = c.slice(8..-1).downcase.to_sym
|
44
45
|
|
45
|
-
|
46
|
+
env_key = "#{ENV_PREFIX}_#{key}".upcase
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
[key, ENV[env_key] || Config.const_get(c)]
|
49
|
+
end
|
49
50
|
]
|
50
51
|
end
|
51
52
|
|
data/lib/philotic/connection.rb
CHANGED
data/lib/philotic/version.rb
CHANGED
@@ -15,7 +15,6 @@ describe Philotic::Connection do
|
|
15
15
|
expect(subject).to receive(:set_exchange_return_handler!)
|
16
16
|
|
17
17
|
subject.connect!
|
18
|
-
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
@@ -27,7 +26,6 @@ describe Philotic::Connection do
|
|
27
26
|
expect(Philotic.logger).to receive(:error)
|
28
27
|
|
29
28
|
subject.connect!
|
30
|
-
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
@@ -40,7 +38,6 @@ describe Philotic::Connection do
|
|
40
38
|
expect(subject).not_to receive(:set_exchange_return_handler!)
|
41
39
|
|
42
40
|
subject.connect!
|
43
|
-
|
44
41
|
end
|
45
42
|
end
|
46
43
|
end
|
@@ -55,4 +52,16 @@ describe Philotic::Connection do
|
|
55
52
|
Philotic::Connection.start_connection!
|
56
53
|
end
|
57
54
|
end
|
55
|
+
|
56
|
+
describe '.close' do
|
57
|
+
let(:connection) { double }
|
58
|
+
specify do
|
59
|
+
allow(Philotic::Connection).to receive(:connection).and_return(connection)
|
60
|
+
expect(connection).to receive(:connected?).and_return(true)
|
61
|
+
expect(connection).to receive(:close)
|
62
|
+
expect(Philotic::Connection.instance_variable_get(:@channel)).to eq(nil)
|
63
|
+
expect(Philotic::Connection.instance_variable_get(:@exchange)).to eq(nil)
|
64
|
+
Philotic::Connection.close
|
65
|
+
end
|
66
|
+
end
|
58
67
|
end
|
@@ -2,12 +2,14 @@ require 'spec_helper'
|
|
2
2
|
require 'philotic/dummy_event'
|
3
3
|
|
4
4
|
describe Philotic::Publisher do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
let(:event) do
|
6
|
+
event = Philotic::DummyEvent.new
|
7
|
+
event.subject = 'Hello'
|
8
|
+
event.message = 'How are you?'
|
9
|
+
event.gender = :M
|
10
|
+
event.available = true
|
11
|
+
|
12
|
+
event
|
11
13
|
end
|
12
14
|
let(:publisher) { Philotic::Publisher }
|
13
15
|
subject { publisher }
|
@@ -21,6 +23,7 @@ describe Philotic::Publisher do
|
|
21
23
|
|
22
24
|
describe 'publish' do
|
23
25
|
it 'should call _publish with the right values' do
|
26
|
+
Timecop.freeze
|
24
27
|
expect(subject).to receive(:_publish).with(
|
25
28
|
{
|
26
29
|
subject: 'Hello',
|
@@ -38,7 +41,7 @@ describe Philotic::Publisher do
|
|
38
41
|
timestamp: Time.now.to_i
|
39
42
|
}
|
40
43
|
)
|
41
|
-
subject.publish(
|
44
|
+
subject.publish(event)
|
42
45
|
end
|
43
46
|
|
44
47
|
end
|
@@ -46,43 +49,46 @@ describe Philotic::Publisher do
|
|
46
49
|
describe 'raw_publish' do
|
47
50
|
|
48
51
|
it 'should call exchange.publish with the right values' do
|
52
|
+
Timecop.freeze
|
49
53
|
exchange = double
|
50
54
|
expect(Philotic::Connection).to receive(:exchange).and_return(exchange)
|
51
55
|
|
52
56
|
expect(Philotic).to receive(:connect!)
|
53
57
|
expect(Philotic::Connection).to receive(:connected?).and_return(true)
|
58
|
+
metadata = {
|
59
|
+
routing_key: nil,
|
60
|
+
persistent: true,
|
61
|
+
mandatory: true,
|
62
|
+
content_type: nil,
|
63
|
+
content_encoding: nil,
|
64
|
+
priority: nil,
|
65
|
+
message_id: nil,
|
66
|
+
correlation_id: nil,
|
67
|
+
reply_to: nil,
|
68
|
+
type: nil,
|
69
|
+
user_id: nil,
|
70
|
+
app_id: nil,
|
71
|
+
expiration: nil,
|
72
|
+
headers: {
|
73
|
+
philotic_firehose: true,
|
74
|
+
philotic_product: nil,
|
75
|
+
philotic_component: nil,
|
76
|
+
philotic_event_type: nil,
|
77
|
+
gender: :M,
|
78
|
+
available: true
|
79
|
+
},
|
80
|
+
timestamp: Time.now.to_i
|
81
|
+
}
|
82
|
+
|
54
83
|
|
55
84
|
expect(exchange).to receive(:publish).with(
|
56
85
|
{
|
57
86
|
subject: 'Hello',
|
58
87
|
message: 'How are you?'
|
59
88
|
}.to_json,
|
60
|
-
|
61
|
-
routing_key: nil,
|
62
|
-
persistent: true,
|
63
|
-
mandatory: true,
|
64
|
-
content_type: nil,
|
65
|
-
content_encoding: nil,
|
66
|
-
priority: nil,
|
67
|
-
message_id: nil,
|
68
|
-
correlation_id: nil,
|
69
|
-
reply_to: nil,
|
70
|
-
type: nil,
|
71
|
-
user_id: nil,
|
72
|
-
app_id: nil,
|
73
|
-
expiration: nil,
|
74
|
-
headers: {
|
75
|
-
philotic_firehose: true,
|
76
|
-
philotic_product: nil,
|
77
|
-
philotic_component: nil,
|
78
|
-
philotic_event_type: nil,
|
79
|
-
gender: :M,
|
80
|
-
available: true
|
81
|
-
},
|
82
|
-
timestamp: Time.now.to_i
|
83
|
-
}
|
89
|
+
metadata
|
84
90
|
)
|
85
|
-
subject.publish(
|
91
|
+
subject.publish(event)
|
86
92
|
end
|
87
93
|
|
88
94
|
it 'should log an error when there is no connection' do
|
@@ -92,7 +98,7 @@ describe Philotic::Publisher do
|
|
92
98
|
expect(Philotic::Connection).to receive(:connected?).once.and_return(false)
|
93
99
|
|
94
100
|
expect(Philotic.logger).to receive(:error)
|
95
|
-
subject.publish(
|
101
|
+
subject.publish(event)
|
96
102
|
end
|
97
103
|
|
98
104
|
end
|
data/spec/philotic_spec.rb
CHANGED
@@ -24,17 +24,19 @@ describe Philotic do
|
|
24
24
|
}
|
25
25
|
}
|
26
26
|
end
|
27
|
-
it
|
28
|
-
|
27
|
+
it 'should throw an error when Philotic::Config.initialize_named_queues is falsey' do
|
28
|
+
allow(Philotic::Config).to receive(:initialize_named_queues).and_return(nil)
|
29
29
|
queue_name = test_queues.keys.first
|
30
30
|
config = test_queues[queue_name]
|
31
31
|
expect(Philotic).not_to receive(:connect!)
|
32
|
-
expect { Philotic.initialize_named_queue! queue_name, config }.to raise_error
|
32
|
+
expect { Philotic.initialize_named_queue! queue_name, config }.to raise_error
|
33
33
|
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
|
36
|
+
it 'should log a warning when Philotic::Config.delete_existing_queues is falsey and the queue already exists' do
|
37
|
+
allow(Philotic::Config).to receive(:initialize_named_queues).and_return(true)
|
38
|
+
allow(Philotic::Config).to receive(:delete_existing_queues).and_return(nil)
|
39
|
+
|
38
40
|
test_queues.each_pair do |queue_name, config|
|
39
41
|
|
40
42
|
connection = double
|
@@ -49,9 +51,9 @@ describe Philotic do
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
|
-
it
|
53
|
-
|
54
|
-
|
54
|
+
it 'should delete the queue first when Philotic::Config.delete_existing_queues is truthy and the queue already exists' do
|
55
|
+
allow(Philotic::Config).to receive(:initialize_named_queues).and_return(true)
|
56
|
+
allow(Philotic::Config).to receive(:delete_existing_queues).and_return(true)
|
55
57
|
|
56
58
|
test_queues.each_pair do |queue_name, config|
|
57
59
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: philotic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Keyes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-18 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: codeclimate-test-reporter
|