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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee1d9812c7c6660194339252c4bf0937e5b61835
4
- data.tar.gz: 67e432c035d71d4e0c225a6fc6f7bb4007df302e
3
+ metadata.gz: a60ac5e8053afb45e0459396f2b03ddf13a24f59
4
+ data.tar.gz: daed056c818497be3ac3990bee70c236df0f197a
5
5
  SHA512:
6
- metadata.gz: f03f343eb79f3b7408fcd55eb8a94c756b6955c5afa3df8d6a9bf2f97a1508cd4122a28b203ddd8cb0d744c864e5d25d668c043d48bef1b0692449cc4340c391
7
- data.tar.gz: 106f0215edb60b7a1b8011984e0498533db8e1ca41c25dd316c4b1ecb7c057f53216ce66aec2fa74905d04245b26a58cbea42e6314d40c856a642ad033f2f6c5
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
 
@@ -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 = true
29
- # DEFAULT_IMMEDIATE = false
30
- DEFAULT_MANDATORY = true
31
- DEFAULT_CONTENT_TYPE = nil
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; host:#{rabbit_host}" }
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; host:#{rabbit_host}" }
101
+ logger.warn { "RabbitMQ connection loss: #{sanitized_rabbit_url}" }
97
102
  conn.reconnect(false, 2)
98
103
  end
99
104
  end
@@ -82,7 +82,7 @@ module Philotic
82
82
  def connection_settings
83
83
  {
84
84
  timeout: config.timeout.to_i,
85
- automatically_recover: true,
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, :publish
171
- def_delegators :subscriber, :subscribe
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
@@ -13,7 +13,7 @@ module Philotic
13
13
  MESSAGE_OPTIONS = [
14
14
  :routing_key,
15
15
  :persistent,
16
- # :immediate,
16
+ :immediate,
17
17
  :mandatory,
18
18
  :content_type,
19
19
  :content_encoding,
@@ -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 subscription_callback(&block)
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(Metadata.new(metadata), event, &block)
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
- @exchange = connection.exchange
37
+ connection.channel.prefetch(connection.config.prefetch_count)
41
38
 
42
39
  subscription_settings = get_subscription_settings subscription, subscribe_options
43
40
 
44
- q = connection.channel.queue(subscription_settings[:queue_name], subscription_settings[:queue_options])
41
+ queue = initialize_queue(subscription_settings)
42
+
43
+ queue.subscribe(subscription_settings[:subscribe_options], &subscription_callback(queue, &block))
45
44
 
46
- q.bind(@exchange, arguments: subscription_settings[:arguments]) if subscription_settings[:arguments]
45
+ end
47
46
 
48
- q.subscribe(subscription_settings[:subscribe_options], &subscription_callback(&block))
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)
@@ -1,3 +1,3 @@
1
1
  module Philotic
2
- VERSION = '0.7.2'
2
+ VERSION = '0.8.0'
3
3
  end
data/philotic.yml.example CHANGED
@@ -11,9 +11,9 @@ defaults: &defaults
11
11
 
12
12
  #message settings
13
13
  routing_key: ~
14
- persistent: true
15
- # immediate: true
16
- mandatory: true
14
+ persistent: false
15
+ immediate: false
16
+ mandatory: false
17
17
  content_type: ~
18
18
  content_encoding: ~
19
19
  priority: ~
@@ -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: true,
86
- mandatory: true,
87
- content_type: nil,
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(:exchange).and_return(exchange)
28
- expect(subject.connection).to receive(:channel).and_return(channel)
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.7.2
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-02 00:00:00 Z
12
+ date: 2015-01-08 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: codeclimate-test-reporter