basquiat 1.3.6 → 1.4.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
  SHA256:
3
- metadata.gz: 8ed5c7487ac314bdec3f560a81a8b4e4097e814540c92ce0fd0f19d218a79e8e
4
- data.tar.gz: 2eb0ecfca39ad4967f454b286df5e0025ca704c598287e044792bb8d55e8af91
3
+ metadata.gz: c58b903c923eb880488c658ccd185076edac51ccc279cdc3e03833676a6a1770
4
+ data.tar.gz: c68e49c4012d1d52b199d22df0ce6a04cfd9f551361e516e927f8679d0cc9719
5
5
  SHA512:
6
- metadata.gz: 55b03873df8ff51be38faf9629812c31039d1c2d974a93e5656f99d3f53c65a8620bb9507d681d48fb98b34bca2ee2f9ce88053d3dbb9797cab1100a5ed7d6b8
7
- data.tar.gz: 6d568ed0f4fdbc4687076804bd6c2d41e21f0d48c19b218905b8f1544c6e4d26757eb08b3a5e20104eb4b082aa52acc99ad9b2e02f42860b5cfe1d98dc06397d
6
+ metadata.gz: 99dee9a41070083aa8cc9c8f1dd762444684246c4592e97ea6b26b2eee35be88cb200d5704e1771bb076be0f1cce6a58b3796f99675d589ea3d47baf0167d102
7
+ data.tar.gz: 5299eba89ddd38bbaeb081aa8bae8ddeede2614b95745c42a68c5e71a8aaaa974406b2e5fb33b212a54fe06e820e1b9cfa897f3495a9127747f5c18fd28d0a4e
data/README.md CHANGED
@@ -106,6 +106,9 @@ development: #full example of the RabbitMq option
106
106
  publisher:
107
107
  confirm: true
108
108
  persistent: true
109
+ session_pool:
110
+ size: 10
111
+ timeout: 5
109
112
  requeue:
110
113
  enabled: true
111
114
  strategy: delayed_delivery
@@ -37,6 +37,7 @@ EOD
37
37
  spec.add_development_dependency 'codeclimate-test-reporter'
38
38
  spec.add_development_dependency 'yard'
39
39
 
40
+ spec.add_dependency 'connection_pool'
40
41
  spec.add_dependency 'multi_json'
41
42
  spec.add_dependency 'naught'
42
43
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'connection_pool'
3
4
  require 'multi_json'
4
5
  require 'naught'
5
6
  require 'yaml'
@@ -22,7 +22,7 @@ module Basquiat
22
22
  durable: true,
23
23
  options: {}
24
24
  },
25
- publisher: { confirm: true, persistent: false },
25
+ publisher: { confirm: true, persistent: false, session_pool: { size: 1, timeout: 5 } },
26
26
  consumer: { prefetch: 1000, manual_ack: true },
27
27
  requeue: { enabled: false } }
28
28
  end
@@ -43,7 +43,7 @@ module Basquiat
43
43
  # @param message [Hash] the message to be publish
44
44
  # @param props [Hash] other properties you wish to publish with the message, such as custom headers etc.
45
45
  def publish(event, message, props: {})
46
- session.publish(event, message, props)
46
+ session_pool.with { |session| session.publish(event, message, props) }
47
47
  disconnect unless options[:publisher][:persistent]
48
48
  end
49
49
 
@@ -67,9 +67,10 @@ module Basquiat
67
67
  # Reset the connection to RabbitMQ.
68
68
  def reset_connection
69
69
  connection.disconnect
70
- @connection = nil
71
- @session = nil
72
- @strategy = nil
70
+ @connection = nil
71
+ @session = nil
72
+ @session_pool = nil
73
+ @strategy = nil
73
74
  end
74
75
 
75
76
  alias disconnect reset_connection
@@ -86,6 +87,15 @@ module Basquiat
86
87
  @session ||= Session.new(connection.create_channel, @configuration.session_options)
87
88
  end
88
89
 
90
+ # Lazy initializes and return the session pool
91
+ # @return [ConnectionPool<Session>]
92
+ def session_pool
93
+ @session_pool ||= ConnectionPool.new(size: options[:publisher][:session_pool][:size],
94
+ timeout: options[:publisher][:session_pool][:timeout]) do
95
+ Session.new(connection.create_channel, @configuration.session_options)
96
+ end
97
+ end
98
+
89
99
  private
90
100
 
91
101
  # Lazy initializes the connection
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Version file
4
4
  module Basquiat
5
- VERSION = '1.3.6'
5
+ VERSION = '1.4.0'
6
6
  end
@@ -22,10 +22,32 @@ RSpec.describe Basquiat::Adapters::RabbitMq do
22
22
  end
23
23
 
24
24
  context 'publisher' do
25
- it '#publish [enqueue a message]' do
26
- expect do
27
- adapter.publish('messages.welcome', data: 'A Nice Welcome Message')
28
- end.to_not raise_error
25
+ context 'main process' do
26
+ it '#publish [enqueue a message]' do
27
+ expect do
28
+ adapter.publish('messages.welcome', data: 'A Nice Welcome Message')
29
+ end.to_not raise_error
30
+ end
31
+ end
32
+
33
+ context 'multiple threads' do
34
+ let(:base_options) do
35
+ { connection: { hosts: [ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' }],
36
+ port: ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_PORT') { 5672 } },
37
+ publisher: { persistent: true, session_pool: { size: 10 } } }
38
+ end
39
+
40
+ it '#publish [enqueue a message 10 times concurrently]' do
41
+ expect do
42
+ threads = []
43
+
44
+ 10.times do
45
+ threads << Thread.new { adapter.publish('messages.welcome', data: 'A Nice Welcome Message') }
46
+ end
47
+
48
+ threads.each(&:join)
49
+ end.not_to raise_error
50
+ end
29
51
  end
30
52
  end
31
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basquiat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcello "mereghost" Rocha
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-11 00:00:00.000000000 Z
12
+ date: 2018-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -221,6 +221,20 @@ dependencies:
221
221
  - - ">="
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
+ - !ruby/object:Gem::Dependency
225
+ name: connection_pool
226
+ requirement: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ type: :runtime
232
+ prerelease: false
233
+ version_requirements: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
224
238
  - !ruby/object:Gem::Dependency
225
239
  name: multi_json
226
240
  requirement: !ruby/object:Gem::Requirement