philotic 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/philotic/config.rb +11 -6
- data/lib/philotic/connection.rb +3 -3
- data/lib/philotic/constants.rb +1 -1
- data/lib/philotic/subscriber.rb +15 -13
- data/lib/philotic/version.rb +1 -1
- data/philotic.yml.example +3 -3
- data/spec/philotic/publisher_spec.rb +4 -8
- data/spec/philotic/subscriber_spec.rb +4 -3
- 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: a60ac5e8053afb45e0459396f2b03ddf13a24f59
|
4
|
+
data.tar.gz: daed056c818497be3ac3990bee70c236df0f197a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 169e1c7a78948103445daff4d1fe69d6caad5851180f842b26ff5d4d0d35a3804b240b99a0ce9d22a532803f30362e1c1949fd5a4cf67cc6c3a28d300d4c359c
|
7
|
+
data.tar.gz: 4bf8d7a2832ffa99f0633e8f18693c24d31eb7eaff8789bdc409a8f7bd14c0329e540ec6e6477b72d728fad1eb51131c74f51d34ee9ef7369e21e23ea8c53b0c
|
data/README.md
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
Lightweight, opinionated wrapper for using RabbitMQ headers exchanges
|
4
4
|
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/philotic.png)](http://badge.fury.io/rb/philotic)
|
6
5
|
[![Build Status](https://travis-ci.org/nkeyes/philotic.png?branch=master)](https://travis-ci.org/nkeyes/philotic)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/philotic.png)](http://badge.fury.io/rb/philotic)
|
7
|
+
[![Dependency Status](https://gemnasium.com/nkeyes/philotic.svg)](https://gemnasium.com/nkeyes/philotic)
|
7
8
|
[![Code Climate](https://codeclimate.com/github/nkeyes/philotic/badges/gpa.svg)](https://codeclimate.com/github/nkeyes/philotic)
|
8
9
|
[![Test Coverage](https://codeclimate.com/github/nkeyes/philotic/badges/coverage.svg)](https://codeclimate.com/github/nkeyes/philotic)
|
9
10
|
|
data/lib/philotic/config.rb
CHANGED
@@ -25,10 +25,10 @@ module Philotic
|
|
25
25
|
DEFAULT_EXCHANGE_NAME = 'philotic.headers'
|
26
26
|
DEFAULT_TIMEOUT = 2
|
27
27
|
DEFAULT_ROUTING_KEY = nil
|
28
|
-
DEFAULT_PERSISTENT =
|
29
|
-
|
30
|
-
DEFAULT_MANDATORY =
|
31
|
-
DEFAULT_CONTENT_TYPE =
|
28
|
+
DEFAULT_PERSISTENT = false
|
29
|
+
DEFAULT_IMMEDIATE = false
|
30
|
+
DEFAULT_MANDATORY = false
|
31
|
+
DEFAULT_CONTENT_TYPE = 'application/json'
|
32
32
|
DEFAULT_CONTENT_ENCODING = nil
|
33
33
|
DEFAULT_PRIORITY = nil
|
34
34
|
DEFAULT_MESSAGE_ID = nil
|
@@ -40,6 +40,7 @@ module Philotic
|
|
40
40
|
DEFAULT_TIMESTAMP = nil
|
41
41
|
DEFAULT_EXPIRATION = nil
|
42
42
|
DEFAULT_CONNECTION_ATTEMPTS = 3
|
43
|
+
DEFAULT_PREFETCH_COUNT = 1
|
43
44
|
|
44
45
|
attr_accessor :connection
|
45
46
|
|
@@ -83,17 +84,21 @@ module Philotic
|
|
83
84
|
@connection_retries ||= defaults[:connection_attempts].to_i
|
84
85
|
end
|
85
86
|
|
87
|
+
def prefetch_count
|
88
|
+
@prefetch_count ||= defaults[:prefetch_count].to_i
|
89
|
+
end
|
90
|
+
|
86
91
|
attr_writer :connection_failed_handler, :connection_loss_handler, :message_return_handler
|
87
92
|
|
88
93
|
def connection_failed_handler
|
89
94
|
@connection_failed_handler ||= lambda do |settings|
|
90
|
-
logger.error { "RabbitMQ connection failure
|
95
|
+
logger.error { "RabbitMQ connection failure: #{sanitized_rabbit_url}" }
|
91
96
|
end
|
92
97
|
end
|
93
98
|
|
94
99
|
def connection_loss_handler
|
95
100
|
@connection_loss_handler ||= lambda do |conn, settings|
|
96
|
-
logger.warn { "RabbitMQ connection loss
|
101
|
+
logger.warn { "RabbitMQ connection loss: #{sanitized_rabbit_url}" }
|
97
102
|
conn.reconnect(false, 2)
|
98
103
|
end
|
99
104
|
end
|
data/lib/philotic/connection.rb
CHANGED
@@ -82,7 +82,7 @@ module Philotic
|
|
82
82
|
def connection_settings
|
83
83
|
{
|
84
84
|
timeout: config.timeout.to_i,
|
85
|
-
|
85
|
+
automatic_recovery: true,
|
86
86
|
on_tcp_connection_failure: config.connection_failed_handler,
|
87
87
|
}
|
88
88
|
end
|
@@ -167,7 +167,7 @@ module Philotic
|
|
167
167
|
@logger
|
168
168
|
end
|
169
169
|
|
170
|
-
def_delegators :publisher, :
|
171
|
-
def_delegators :subscriber, :
|
170
|
+
def_delegators :publisher, *(Philotic::Publisher.public_instance_methods(false) - [:connection, :config, :logger])
|
171
|
+
def_delegators :subscriber, *(Philotic::Subscriber.public_instance_methods(false) - [:connection, :config, :logger])
|
172
172
|
end
|
173
173
|
end
|
data/lib/philotic/constants.rb
CHANGED
data/lib/philotic/subscriber.rb
CHANGED
@@ -2,13 +2,6 @@ require 'philotic/constants'
|
|
2
2
|
|
3
3
|
module Philotic
|
4
4
|
class Subscriber
|
5
|
-
class Metadata
|
6
|
-
attr_accessor :attributes
|
7
|
-
|
8
|
-
def initialize(attributes)
|
9
|
-
self.attributes = attributes
|
10
|
-
end
|
11
|
-
end
|
12
5
|
|
13
6
|
attr_accessor :connection
|
14
7
|
|
@@ -20,7 +13,11 @@ module Philotic
|
|
20
13
|
connection.logger
|
21
14
|
end
|
22
15
|
|
23
|
-
def
|
16
|
+
def config
|
17
|
+
connection.config
|
18
|
+
end
|
19
|
+
|
20
|
+
def subscription_callback(queue, &block)
|
24
21
|
lambda do |delivery_info, metadata, payload|
|
25
22
|
hash_payload = JSON.parse payload
|
26
23
|
|
@@ -31,22 +28,27 @@ module Philotic
|
|
31
28
|
attributes: metadata[:headers] ? hash_payload.merge(metadata[:headers]) : hash_payload
|
32
29
|
}
|
33
30
|
|
34
|
-
instance_exec(
|
31
|
+
instance_exec(event, metadata, queue, &block)
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
35
|
def subscribe(subscription = {}, subscribe_options = Philotic::DEFAULT_SUBSCRIBE_OPTIONS, &block)
|
39
36
|
connection.connect!
|
40
|
-
|
37
|
+
connection.channel.prefetch(connection.config.prefetch_count)
|
41
38
|
|
42
39
|
subscription_settings = get_subscription_settings subscription, subscribe_options
|
43
40
|
|
44
|
-
|
41
|
+
queue = initialize_queue(subscription_settings)
|
42
|
+
|
43
|
+
queue.subscribe(subscription_settings[:subscribe_options], &subscription_callback(queue, &block))
|
45
44
|
|
46
|
-
|
45
|
+
end
|
47
46
|
|
48
|
-
|
47
|
+
def initialize_queue(subscription_settings)
|
48
|
+
queue = connection.channel.queue(subscription_settings[:queue_name], subscription_settings[:queue_options])
|
49
49
|
|
50
|
+
queue.bind(connection.exchange, arguments: subscription_settings[:arguments]) if subscription_settings[:arguments]
|
51
|
+
queue
|
50
52
|
end
|
51
53
|
|
52
54
|
def get_subscription_settings(subscription, subscribe_options)
|
data/lib/philotic/version.rb
CHANGED
data/philotic.yml.example
CHANGED
@@ -66,9 +66,7 @@ describe Philotic::Publisher do
|
|
66
66
|
subject.publish(event)
|
67
67
|
expect(event).to_not be_published
|
68
68
|
end
|
69
|
-
|
70
69
|
end
|
71
|
-
|
72
70
|
end
|
73
71
|
|
74
72
|
describe '#raw_publish' do
|
@@ -82,9 +80,10 @@ describe Philotic::Publisher do
|
|
82
80
|
expect(subject.connection).to receive(:connected?).and_return(true)
|
83
81
|
metadata = {
|
84
82
|
routing_key: nil,
|
85
|
-
persistent:
|
86
|
-
|
87
|
-
|
83
|
+
persistent: false,
|
84
|
+
immediate: false,
|
85
|
+
mandatory: false,
|
86
|
+
content_type: 'application/json',
|
88
87
|
content_encoding: nil,
|
89
88
|
priority: nil,
|
90
89
|
message_id: nil,
|
@@ -120,7 +119,6 @@ describe Philotic::Publisher do
|
|
120
119
|
|
121
120
|
it 'should log an error when there is no connection' do
|
122
121
|
|
123
|
-
|
124
122
|
expect(subject.connection).to receive(:connect!)
|
125
123
|
expect(subject.connection).to receive(:connected?).once.and_return(false)
|
126
124
|
|
@@ -132,7 +130,6 @@ describe Philotic::Publisher do
|
|
132
130
|
|
133
131
|
end
|
134
132
|
|
135
|
-
|
136
133
|
describe '#normalize_payload_times' do
|
137
134
|
let(:responds_to_utc) { double }
|
138
135
|
let(:responds_to_to_utc) { double }
|
@@ -153,6 +150,5 @@ describe Philotic::Publisher do
|
|
153
150
|
expect(payload).to eq normalized_payload
|
154
151
|
|
155
152
|
end
|
156
|
-
|
157
153
|
end
|
158
154
|
end
|
@@ -24,8 +24,8 @@ describe Philotic::Subscriber do
|
|
24
24
|
|
25
25
|
expect(subject.connection).to receive(:connect!)
|
26
26
|
|
27
|
-
expect(subject.connection).to receive(:
|
28
|
-
expect(
|
27
|
+
expect(subject.connection).to receive(:channel).and_return(channel).twice
|
28
|
+
expect(channel).to receive(:prefetch).with(subject.connection.config.prefetch_count)
|
29
29
|
expect(channel).to receive(:queue).and_return(queue)
|
30
30
|
|
31
31
|
expect(queue).not_to receive(:bind)
|
@@ -57,7 +57,8 @@ describe Philotic::Subscriber do
|
|
57
57
|
expect(subject.connection).to receive(:connect!)
|
58
58
|
|
59
59
|
expect(subject.connection).to receive(:exchange).and_return(exchange)
|
60
|
-
expect(subject.connection).to receive(:channel).and_return(channel)
|
60
|
+
expect(subject.connection).to receive(:channel).and_return(channel).twice
|
61
|
+
expect(channel).to receive(:prefetch).with(subject.connection.config.prefetch_count)
|
61
62
|
expect(channel).to receive(:queue).and_return(queue)
|
62
63
|
|
63
64
|
expect(queue).to receive(:bind).with(exchange, hash_including(arguments: subscription))
|
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.
|
4
|
+
version: 0.8.0
|
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: 2015-01-
|
12
|
+
date: 2015-01-08 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: codeclimate-test-reporter
|