harmoniser 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -7
- data/README.md +0 -2
- data/lib/harmoniser/channelable.rb +14 -2
- data/lib/harmoniser/cli.rb +3 -5
- data/lib/harmoniser/configurable.rb +1 -1
- data/lib/harmoniser/configuration.rb +4 -31
- data/lib/harmoniser/connectable.rb +49 -0
- data/lib/harmoniser/connection.rb +29 -2
- data/lib/harmoniser/launcher.rb +1 -10
- data/lib/harmoniser/loggable.rb +10 -0
- data/lib/harmoniser/version.rb +1 -1
- data/lib/harmoniser.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b56f94d1422e43dd7f7505516400c8f5949998dd8e4a1c8ec36c7c2f5a9ae9f0
|
4
|
+
data.tar.gz: fa96845e13121f315b6af48ef5b765272d00f4ea62ab32a4b3da91ef2eaab712
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 884789f7ccbb0fb23577ed739d352bc332fd9ef8064e9df0c4b355bead5b51b62c563328ac307409fe53481b68990f77f5f7ef34959d6cbc5a00bf364fb9e1ef
|
7
|
+
data.tar.gz: 30c55195bad1e6fe12d213377abeb8c25178e838a7745346e6858ced90efa67eb925a028324cce0361d403aad2c249141cbb0be6376383a4e17a443c8051a542
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,27 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.5.0] - 2023-12-20
|
4
4
|
|
5
5
|
### Added
|
6
|
+
- Setup at_exit hook to be executed when Harmoniser exits for an opened RabbitMQ connection
|
7
|
+
- Add defaults to Bunny::Session for timeouts and recovery attempts
|
8
|
+
- Fix boot up problems for payments application example
|
9
|
+
- Perform refactoring of internals such as slimming down Configuration
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
-
|
11
|
+
## [0.4.0] - 2023-12-07
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- Default logger with error severity for when errors occur at channel level
|
15
|
+
- Default logger with error severity for when errors occur while processing a message from a queue
|
16
|
+
|
17
|
+
### Removed
|
18
|
+
- Unused docker image for rabbitMQ (only for development purposes)
|
19
|
+
|
20
|
+
## [0.3.0] - 2023-11-29
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- Introduce github action for building, linting and running specs anytime a pull request is opened or push to master happens
|
11
25
|
|
12
26
|
## [0.2.0] - 2023-11-28
|
13
27
|
|
@@ -15,8 +29,11 @@
|
|
15
29
|
|
16
30
|
- Introduce github action for releasing the gem once is merged into master
|
17
31
|
|
18
|
-
## [0.
|
32
|
+
## [0.1.0] - 2023-11-27
|
19
33
|
|
20
34
|
### Added
|
21
35
|
|
22
|
-
-
|
36
|
+
- Support to express publishing through any kind of exchanges
|
37
|
+
- Capability to subscribe to queues
|
38
|
+
- Express RabbitMQ topology separated from the responsibility of publishing or subscribing
|
39
|
+
- Provide dedicated Ruby process to consume messages through the subscribers defined
|
data/README.md
CHANGED
@@ -123,9 +123,7 @@ You can also shell into the running container by executing `$ make shell` and fr
|
|
123
123
|
|
124
124
|
- [ ] Issue: Reopen memoized Channel in the context of the class that are included. There are scenarios for which the channel gets closed, for instance Precondition Failed when checking an exchange declaration.
|
125
125
|
- [ ] Chore: Introduce simplecov gem for code coverage.
|
126
|
-
- [ ] Feature: Add sensible defaults for Session options like heartbeat, timeout, recovery_completed or recovery_attempt_started.
|
127
126
|
- [ ] Feature: Add default `on_return` handler as well as permitting the definition of on_return method to be called anytime a published message gets returned.
|
128
|
-
- [ ] Feature: Add default `on_error` and `on_uncaught_exception` as well as permitting the definition of them to be called anytime an error in the channel occurs or error in the consumer handler happens.
|
129
127
|
- [ ] Feature: Introduce capability of configuring number of threads for queue consuming at the CLI.
|
130
128
|
|
131
129
|
## License
|
@@ -11,8 +11,20 @@ module Harmoniser
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def create_channel
|
14
|
-
|
15
|
-
|
14
|
+
channel = Harmoniser.connection.create_channel
|
15
|
+
channel.on_error(&method(:on_error).to_proc)
|
16
|
+
channel.on_uncaught_exception(&method(:on_uncaught_exception).to_proc)
|
17
|
+
channel
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def on_error(channel, amq_method)
|
23
|
+
Harmoniser.logger.error("Default on_error handler executed for channel: method = `#{amq_method}`, exchanges = `#{channel.exchanges.keys}`, queues = `#{channel.queues.keys}`")
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_uncaught_exception(error, consumer)
|
27
|
+
Harmoniser.logger.error("Default on_uncaught_exception handler executed for channel: error_class = `#{error.class}`, error_message = `#{error.message}`, error_backtrace = `#{error.backtrace&.first(5)}, queue = `#{consumer.queue}`")
|
16
28
|
end
|
17
29
|
end
|
18
30
|
|
data/lib/harmoniser/cli.rb
CHANGED
@@ -46,19 +46,17 @@ module Harmoniser
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def run
|
49
|
-
|
50
|
-
|
49
|
+
Launcher
|
50
|
+
.new(configuration: configuration, logger: logger)
|
51
|
+
.start
|
51
52
|
|
52
53
|
while @read_io.wait_readable
|
53
54
|
signal = @read_io.gets.strip
|
54
55
|
handle_signal(signal)
|
55
56
|
end
|
56
57
|
rescue Interrupt
|
57
|
-
logger.info("Shutting down!")
|
58
|
-
launcher.stop
|
59
58
|
@write_io.close
|
60
59
|
@read_io.close
|
61
|
-
logger.info("Bye!")
|
62
60
|
exit(0)
|
63
61
|
end
|
64
62
|
|
@@ -1,33 +1,20 @@
|
|
1
1
|
require "forwardable"
|
2
|
-
require "
|
3
|
-
require "harmoniser/connection"
|
2
|
+
require "harmoniser/connectable"
|
4
3
|
require "harmoniser/topology"
|
5
4
|
require "harmoniser/options"
|
6
5
|
|
7
6
|
module Harmoniser
|
8
7
|
class Configuration
|
9
8
|
extend Forwardable
|
9
|
+
include Connectable
|
10
10
|
|
11
|
-
|
12
|
-
connection_name: "harmoniser@#{VERSION}",
|
13
|
-
host: "127.0.0.1",
|
14
|
-
password: "guest",
|
15
|
-
port: 5672,
|
16
|
-
tls_silence_warnings: true,
|
17
|
-
username: "guest",
|
18
|
-
verify_peer: false,
|
19
|
-
vhost: "/"
|
20
|
-
}
|
21
|
-
MUTEX = Mutex.new
|
22
|
-
|
23
|
-
attr_reader :connection_opts, :logger, :options
|
11
|
+
attr_reader :logger, :options
|
24
12
|
def_delegators :options, :environment, :require, :verbose
|
25
13
|
|
26
14
|
def initialize
|
27
|
-
@logger =
|
15
|
+
@logger = Harmoniser.logger
|
28
16
|
@options = Options.new(**default_options)
|
29
17
|
set_logger_severity
|
30
|
-
@connection_opts = DEFAULT_CONNECTION_OPTS.merge({logger: @logger})
|
31
18
|
@topology = Topology.new
|
32
19
|
end
|
33
20
|
|
@@ -37,20 +24,6 @@ module Harmoniser
|
|
37
24
|
yield(@topology)
|
38
25
|
end
|
39
26
|
|
40
|
-
def connection
|
41
|
-
MUTEX.synchronize do
|
42
|
-
@connection ||= Connection.new(connection_opts)
|
43
|
-
@connection.start unless @connection.open?
|
44
|
-
@connection
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def connection_opts=(opts)
|
49
|
-
raise TypeError, "opts must be a Hash object" unless opts.is_a?(Hash)
|
50
|
-
|
51
|
-
@connection_opts = connection_opts.merge(opts)
|
52
|
-
end
|
53
|
-
|
54
27
|
def options_with(**)
|
55
28
|
@options = options.with(**)
|
56
29
|
set_logger_severity
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "harmoniser/connection"
|
2
|
+
|
3
|
+
module Harmoniser
|
4
|
+
module Connectable
|
5
|
+
MUTEX = Mutex.new
|
6
|
+
|
7
|
+
def connection_opts
|
8
|
+
@connection_opts ||= Connection::DEFAULT_CONNECTION_OPTS.merge({logger: Harmoniser.logger})
|
9
|
+
end
|
10
|
+
|
11
|
+
def connection_opts=(opts)
|
12
|
+
raise TypeError, "opts must be a Hash object" unless opts.is_a?(Hash)
|
13
|
+
|
14
|
+
@connection_opts = connection_opts.merge(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def connection
|
18
|
+
MUTEX.synchronize do
|
19
|
+
@connection ||= create_connection
|
20
|
+
@connection.start unless @connection.open? || @connection.recovering_from_network_failure?
|
21
|
+
@connection
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def connection?
|
26
|
+
!!defined?(@connection)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def create_connection
|
32
|
+
at_exit(&method(:at_exit_handler).to_proc)
|
33
|
+
Connection.new(connection_opts)
|
34
|
+
end
|
35
|
+
|
36
|
+
def at_exit_handler
|
37
|
+
logger = Harmoniser.logger
|
38
|
+
|
39
|
+
logger.info("Shutting down!")
|
40
|
+
if connection? && connection.open?
|
41
|
+
stringified_connection = connection.to_s
|
42
|
+
logger.info("Connection will be closed: connection = `#{stringified_connection}`")
|
43
|
+
connection.close
|
44
|
+
logger.info("Connection closed: connection = `#{stringified_connection}`")
|
45
|
+
end
|
46
|
+
logger.info("Bye!")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -4,18 +4,45 @@ require "bunny"
|
|
4
4
|
module Harmoniser
|
5
5
|
class Connection
|
6
6
|
extend Forwardable
|
7
|
-
|
7
|
+
|
8
|
+
DEFAULT_CONNECTION_OPTS = {
|
9
|
+
connection_name: "harmoniser@#{VERSION}",
|
10
|
+
connection_timout: 5,
|
11
|
+
host: "127.0.0.1",
|
12
|
+
password: "guest",
|
13
|
+
port: 5672,
|
14
|
+
read_timeout: 5,
|
15
|
+
recovery_attempt_started: proc {
|
16
|
+
stringified_connection = Harmoniser.connection.to_s
|
17
|
+
Harmoniser.logger.info("Recovery attempt started: connection = `#{stringified_connection}`")
|
18
|
+
},
|
19
|
+
recovery_completed: proc {
|
20
|
+
stringified_connection = Harmoniser.connection.to_s
|
21
|
+
Harmoniser.logger.info("Recovery completed: connection = `#{stringified_connection}`")
|
22
|
+
},
|
23
|
+
tls_silence_warnings: true,
|
24
|
+
username: "guest",
|
25
|
+
verify_peer: false,
|
26
|
+
vhost: "/",
|
27
|
+
write_timeout: 5
|
28
|
+
}
|
29
|
+
|
30
|
+
def_delegators :@bunny, :close, :create_channel, :open?, :recovering_from_network_failure?, :start
|
8
31
|
|
9
32
|
def initialize(opts)
|
10
33
|
@bunny = Bunny.new(opts)
|
11
34
|
end
|
12
35
|
|
13
36
|
def to_s
|
14
|
-
"<#{self.class.name}>: #{user}@#{host}:#{port}, vhost =
|
37
|
+
"<#{self.class.name}>: #{user}@#{host}:#{port}, connection_name = `#{connection_name}`, vhost = `#{vhost}`"
|
15
38
|
end
|
16
39
|
|
17
40
|
private
|
18
41
|
|
42
|
+
def connection_name
|
43
|
+
@bunny.connection_name
|
44
|
+
end
|
45
|
+
|
19
46
|
def host
|
20
47
|
@bunny.transport.host
|
21
48
|
end
|
data/lib/harmoniser/launcher.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Harmoniser
|
2
2
|
class Launcher
|
3
|
-
def initialize(configuration
|
3
|
+
def initialize(configuration:, logger:)
|
4
4
|
@configuration = configuration
|
5
5
|
@logger = logger
|
6
6
|
end
|
@@ -10,10 +10,6 @@ module Harmoniser
|
|
10
10
|
start_subscribers
|
11
11
|
end
|
12
12
|
|
13
|
-
def stop
|
14
|
-
stop_subscribers
|
15
|
-
end
|
16
|
-
|
17
13
|
private
|
18
14
|
|
19
15
|
def boot_app
|
@@ -33,11 +29,6 @@ module Harmoniser
|
|
33
29
|
@logger.info("Subscribers registered to consume messages from queues: klasses = `#{klasses}`")
|
34
30
|
end
|
35
31
|
|
36
|
-
def stop_subscribers
|
37
|
-
@logger.info("Connection will be closed: connection = `#{@configuration.connection}`")
|
38
|
-
@configuration.connection.close
|
39
|
-
end
|
40
|
-
|
41
32
|
private
|
42
33
|
|
43
34
|
def load_rails
|
data/lib/harmoniser/version.rb
CHANGED
data/lib/harmoniser.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: harmoniser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Lloret
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -89,10 +89,12 @@ files:
|
|
89
89
|
- lib/harmoniser/cli.rb
|
90
90
|
- lib/harmoniser/configurable.rb
|
91
91
|
- lib/harmoniser/configuration.rb
|
92
|
+
- lib/harmoniser/connectable.rb
|
92
93
|
- lib/harmoniser/connection.rb
|
93
94
|
- lib/harmoniser/definition.rb
|
94
95
|
- lib/harmoniser/includable.rb
|
95
96
|
- lib/harmoniser/launcher.rb
|
97
|
+
- lib/harmoniser/loggable.rb
|
96
98
|
- lib/harmoniser/options.rb
|
97
99
|
- lib/harmoniser/parser.rb
|
98
100
|
- lib/harmoniser/publisher.rb
|