harmoniser 0.4.0 → 0.5.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: b1feaead73df2956797f89d33ed45a3316cf5191852946c1b0d3cbe2e2284f18
4
- data.tar.gz: 6ba7ae634d24a012d4243d392d4299a9fd88a35af5df1251efec24bb4817ce9c
3
+ metadata.gz: b56f94d1422e43dd7f7505516400c8f5949998dd8e4a1c8ec36c7c2f5a9ae9f0
4
+ data.tar.gz: fa96845e13121f315b6af48ef5b765272d00f4ea62ab32a4b3da91ef2eaab712
5
5
  SHA512:
6
- metadata.gz: 9cfcdeec3f6e205c9301d5f2142cd8e7fee0723ed5950fdf1bd12a704f1cc29ecf971e39c75ef7ace071ea577a37f45a874c4016a63c561d25c3e206f1fb0e6f
7
- data.tar.gz: 45b409fb2bfa3ec1752101915fad8f52ccf1e5a5ea1402e23ee6fc062e952fbdb78a16015f77bc2ef2ddafda04859eb23d0e9c8c9cef06a9675fe0c44e81f5d5
6
+ metadata.gz: 884789f7ccbb0fb23577ed739d352bc332fd9ef8064e9df0c4b355bead5b51b62c563328ac307409fe53481b68990f77f5f7ef34959d6cbc5a00bf364fb9e1ef
7
+ data.tar.gz: 30c55195bad1e6fe12d213377abeb8c25178e838a7745346e6858ced90efa67eb925a028324cce0361d403aad2c249141cbb0be6376383a4e17a443c8051a542
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0] - 2023-12-20
4
+
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
10
+
3
11
  ## [0.4.0] - 2023-12-07
4
12
 
5
13
  ### Added
data/README.md CHANGED
@@ -123,7 +123,6 @@ 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
127
  - [ ] Feature: Introduce capability of configuring number of threads for queue consuming at the CLI.
129
128
 
@@ -46,19 +46,17 @@ module Harmoniser
46
46
  end
47
47
 
48
48
  def run
49
- launcher = Launcher.new
50
- launcher.start
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
 
@@ -20,6 +20,6 @@ module Harmoniser
20
20
  @configuration ||= Configuration.new
21
21
  end
22
22
 
23
- def_delegators :configuration, :logger, :connection
23
+ def_delegators :configuration, :connection, :connection?
24
24
  end
25
25
  end
@@ -1,33 +1,20 @@
1
1
  require "forwardable"
2
- require "logger"
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
- DEFAULT_CONNECTION_OPTS = {
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 = Logger.new($stdout, progname: "harmoniser@#{VERSION}")
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
- def_delegators :@bunny, :close, :create_channel, :open?, :start
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 = #{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
@@ -1,6 +1,6 @@
1
1
  module Harmoniser
2
2
  class Launcher
3
- def initialize(configuration: Harmoniser.configuration, logger: Harmoniser.logger)
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
@@ -0,0 +1,10 @@
1
+ require "logger"
2
+ require "harmoniser/version"
3
+
4
+ module Harmoniser
5
+ module Loggable
6
+ def logger
7
+ @logger ||= Logger.new($stdout, progname: "harmoniser@#{VERSION}")
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Harmoniser
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/harmoniser.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require "harmoniser/version"
2
2
  require "harmoniser/configurable"
3
+ require "harmoniser/loggable"
3
4
  require "harmoniser/publisher"
4
5
  require "harmoniser/subscriber"
5
6
 
6
7
  module Harmoniser
7
8
  extend Configurable
9
+ extend Loggable
8
10
  end
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.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-12-07 00:00:00.000000000 Z
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