basquiat 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/basquiat/adapters/rabbitmq/configuration.rb +1 -1
- data/lib/basquiat/adapters/rabbitmq/connection.rb +8 -2
- data/lib/basquiat/adapters/rabbitmq_adapter.rb +7 -3
- data/lib/basquiat/support/configuration.rb +3 -1
- data/lib/basquiat/version.rb +1 -1
- data/spec/lib/adapters/rabbitmq_adapter_spec.rb +4 -0
- data/spec/lib/support/configuration_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc25a020cacd1dff67867ecf85f81c82e4feae712aafdcebd26f7076d11c740c
|
4
|
+
data.tar.gz: fc480994ad88edfcb3d61e990e900d32f34e55164aaa149a5e254eeb459db3a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f8442912b5a26b0223c22d8abdc0a580c06d935ed346a4b57092b58c90440de0f2861396ea9e651e4881650adaaed55b210942a653bf3b56481f804c554e335
|
7
|
+
data.tar.gz: 99e0ab18b267398e71c2dc25d0c933e2e6caa939868037e9383a803815a137f7278662f47d7e0902decdf9afd1c82d8cdeffce74ec79dcb1ffa42966e7c50d76
|
data/README.md
CHANGED
@@ -74,6 +74,7 @@ end
|
|
74
74
|
The available options are:
|
75
75
|
|
76
76
|
- config_file= Receive a path to an YAML file (example here)
|
77
|
+
- connection= Makes Basquiat to use a provided Bunny connection
|
77
78
|
- queue_name= The default queue name
|
78
79
|
- exchange_name= The default exchange name
|
79
80
|
- environment= Forces the environment to something other than the value of BASQUIAT_ENV
|
@@ -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 },
|
26
26
|
consumer: { prefetch: 1000, manual_ack: true },
|
27
27
|
requeue: { enabled: false } }
|
28
28
|
end
|
@@ -7,9 +7,12 @@ module Basquiat
|
|
7
7
|
class Connection < SimpleDelegator
|
8
8
|
# @param hosts: [Array<String>] IPs or FQDN of the RabbitMQ instances
|
9
9
|
# @param port [Fixnum] Port that the RabbitMQ instances run
|
10
|
+
# @option failover: [Fixnum|Symbol] :heartbeat (:server) Heartbeat timeout to offer to the server
|
10
11
|
# @option failover: [Fixnum] :max_retries (5) Maximum number of reconnection retries
|
11
12
|
# @option failover: [Fixnum] :default_timeout (5) Interval between to reconnect attempts
|
12
13
|
# @option failover: [Fixnum] :connection_timeout (5) Allowed time before a connection attempt timeouts
|
14
|
+
# @option failover: [Fixnum] :read_timeout (30) TCP socket read timeout in seconds
|
15
|
+
# @option failover: [Fixnum] :write_timeout (30) TCP socket write timeout in seconds
|
13
16
|
# @option auth: [String] :user ('guest')
|
14
17
|
# @option auth: [String] :password ('guest')
|
15
18
|
def initialize(hosts:, port: 5672, failover: {}, auth: {})
|
@@ -22,7 +25,7 @@ module Basquiat
|
|
22
25
|
# Creates a channel
|
23
26
|
# @return [Bunny::Channel]
|
24
27
|
def create_channel
|
25
|
-
connection.start
|
28
|
+
connection.start unless connected?
|
26
29
|
Basquiat.logger.debug 'Creating a new channel'
|
27
30
|
connection.create_channel
|
28
31
|
end
|
@@ -53,14 +56,17 @@ module Basquiat
|
|
53
56
|
end
|
54
57
|
|
55
58
|
def connection
|
56
|
-
@connection ||= Bunny.new(
|
59
|
+
@connection ||= Basquiat.configuration.connection || Bunny.new(
|
57
60
|
hosts: @hosts,
|
58
61
|
port: @port,
|
59
62
|
username: @auth.fetch(:user, 'guest'),
|
60
63
|
password: @auth.fetch(:password, 'guest'),
|
64
|
+
heartbeat: @failover.fetch(:heartbeat, :server),
|
61
65
|
recovery_attempts: @failover.fetch(:max_retries, 5),
|
62
66
|
network_recovery_interval: @failover.fetch(:default_timeout, 5),
|
63
67
|
connection_timeout: @failover.fetch(:connection_timeout, 5),
|
68
|
+
read_timeout: @failover.fetch(:read_timeout, 30),
|
69
|
+
write_timeout: @failover.fetch(:write_timeout, 30),
|
64
70
|
logger: Basquiat.logger
|
65
71
|
)
|
66
72
|
__setobj__(@connection)
|
@@ -43,7 +43,11 @@ 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_pool
|
46
|
+
if options[:publisher][:session_pool]
|
47
|
+
session_pool.with { |session| session.publish(event, message, props) }
|
48
|
+
else
|
49
|
+
session.publish(event, message, props)
|
50
|
+
end
|
47
51
|
disconnect unless options[:publisher][:persistent]
|
48
52
|
end
|
49
53
|
|
@@ -90,8 +94,8 @@ module Basquiat
|
|
90
94
|
# Lazy initializes and return the session pool
|
91
95
|
# @return [ConnectionPool<Session>]
|
92
96
|
def session_pool
|
93
|
-
@session_pool ||= ConnectionPool.new(size: options[:publisher][:session_pool]
|
94
|
-
timeout: options[:publisher][:session_pool]
|
97
|
+
@session_pool ||= ConnectionPool.new(size: options[:publisher][:session_pool].fetch(:size, 1),
|
98
|
+
timeout: options[:publisher][:session_pool].fetch(:timeout, 5)) do
|
95
99
|
Session.new(connection.create_channel, @configuration.session_options)
|
96
100
|
end
|
97
101
|
end
|
@@ -32,10 +32,12 @@ module Basquiat
|
|
32
32
|
# or :development
|
33
33
|
attr_writer :queue_name, :exchange_name, :logger, :environment
|
34
34
|
|
35
|
+
# @!attribute connection - Makes Basquiat to use a provided connection
|
36
|
+
# @return [Object] the provided connection
|
35
37
|
# @!attribute rescue_proc
|
36
38
|
# @return [#call] return the callable to be executed when some exception is thrown. The callable receives the
|
37
39
|
# exception and message
|
38
|
-
attr_accessor :rescue_proc
|
40
|
+
attr_accessor :connection, :rescue_proc
|
39
41
|
|
40
42
|
def queue_name
|
41
43
|
@queue_name || 'basquiat.queue'
|
data/lib/basquiat/version.rb
CHANGED
@@ -37,6 +37,8 @@ RSpec.describe Basquiat::Adapters::RabbitMq do
|
|
37
37
|
publisher: { persistent: true, session_pool: { size: 10 } } }
|
38
38
|
end
|
39
39
|
|
40
|
+
before { Basquiat.configure { |c| c.connection = Bunny.new.tap(&:start) } }
|
41
|
+
|
40
42
|
it '#publish [enqueue a message 10 times concurrently]' do
|
41
43
|
expect do
|
42
44
|
threads = []
|
@@ -48,6 +50,8 @@ RSpec.describe Basquiat::Adapters::RabbitMq do
|
|
48
50
|
threads.each(&:join)
|
49
51
|
end.not_to raise_error
|
50
52
|
end
|
53
|
+
|
54
|
+
after { Basquiat.configure { |c| c.connection = nil } }
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
@@ -37,6 +37,17 @@ RSpec.describe Basquiat::Configuration do
|
|
37
37
|
expect(config.exchange_name).to eq('basquiat.exchange')
|
38
38
|
end
|
39
39
|
|
40
|
+
it '#connection' do
|
41
|
+
expect(config.connection).to be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it '#connection=' do
|
45
|
+
connection = spy('connection')
|
46
|
+
config.connection = connection
|
47
|
+
|
48
|
+
expect(config.connection).to eq(connection)
|
49
|
+
end
|
50
|
+
|
40
51
|
it '#logger' do
|
41
52
|
expect(config.logger).not_to be_nil
|
42
53
|
end
|
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.
|
4
|
+
version: 1.5.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-07-
|
12
|
+
date: 2018-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|