harmoniser 0.5.0 → 0.6.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: b56f94d1422e43dd7f7505516400c8f5949998dd8e4a1c8ec36c7c2f5a9ae9f0
4
- data.tar.gz: fa96845e13121f315b6af48ef5b765272d00f4ea62ab32a4b3da91ef2eaab712
3
+ metadata.gz: 4410b741fa891c42db5f51dc48889768859a9a84a3eed3676fc35f0aaeb8cca1
4
+ data.tar.gz: c6af823a40e9b007f93a347e84ad44aee26dea0e10464fc608c116db7185ec19
5
5
  SHA512:
6
- metadata.gz: 884789f7ccbb0fb23577ed739d352bc332fd9ef8064e9df0c4b355bead5b51b62c563328ac307409fe53481b68990f77f5f7ef34959d6cbc5a00bf364fb9e1ef
7
- data.tar.gz: 30c55195bad1e6fe12d213377abeb8c25178e838a7745346e6858ced90efa67eb925a028324cce0361d403aad2c249141cbb0be6376383a4e17a443c8051a542
6
+ metadata.gz: d843cfe2d70c4ad95cfbe1ce592b7691c057840a191fb7838670eb68205a44549fd7b8e83ff75c2f7888d5c303903f357b93f64c1e37cd5ec342ebb17553051c
7
+ data.tar.gz: 331c5f2133c0e291581ae3f14be398dac07df8adbc43ad72de798171346380f28a084988ff0215922c12783c6e28ec93640dada3ee9aa096ca63ba43a08d2ee3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0] - 2023-12-30
4
+
5
+ ### Added
6
+ - Create a channel for each class including Harmoniser::Publisher or Harmoniser::Subscriber. A mutex in the context of the class including Publisher or Subscriber modules control access to the resources created as well as guarantees safe publication under multi-thread process.
7
+ - Introduce broadcast and unicast examples.
8
+ - Amend specs to wipe out RabbitMQ resources created during spec execution.
9
+
10
+ ### Changed
11
+ - Honour verbose option regardless of the environment configuration set. For instance, for non-production environment, verbose is no longer verbose set by default.
12
+
3
13
  ## [0.5.0] - 2023-12-20
4
14
 
5
15
  ### Added
data/README.md CHANGED
@@ -51,7 +51,7 @@ end
51
51
  MyPublisher.publish({ salute: "Hello World!" }.to_json, routing_key: "my_resource.foo.bar")
52
52
  ```
53
53
 
54
- The code above assumes that the exchange is already defined. We'd like to emphasize that defining RabbitMQ topology (exchanges, queues and binding) should be performed outside of the class whose role is purely focused on publishing. See more details about how to define the topology [here](examples/multicast.rb#L9-L18).
54
+ The code above assumes that the exchange is already defined. We'd like to emphasize that defining RabbitMQ topology (exchanges, queues and binding) should be performed outside of the class whose role is purely focused on publishing. See more details about how to define the topology [here](examples/multicast.rb#L11-L19).
55
55
 
56
56
  ### RabbitMQ
57
57
 
@@ -78,19 +78,10 @@ Harmoniser server is a process specifically dedicated to run Subscribers that ar
78
78
  class MySubscriber
79
79
  include Harmoniser::Subscriber
80
80
  harmoniser_subscriber queue_name: "my_queue"
81
-
82
- class << self
83
- def on_delivery(delivery_info, properties, payload)
84
- Harmoniser.logger.info({
85
- body: "message received",
86
- payload: payload
87
- }.to_json)
88
- end
89
- end
90
81
  end
91
82
  ```
92
83
 
93
- The code above assumes that the queue and its binding to an exchange are already defined. You can see more details about how this is specified [here](examples/multicast.rb#L9-L18).
84
+ The code above assumes that the queue and its binding to an exchange are already defined. You can see more details about how this is specified [here](examples/multicast.rb#L11-L19).
94
85
 
95
86
  In order for the subscribers to receive messages from a queue, you should spin up a dedicated Ruby process like following:
96
87
 
data/docs/cli.md CHANGED
@@ -17,4 +17,4 @@ The `environment` is automatically inferred from the environment variables `RAIL
17
17
 
18
18
  The `require` is by default pointing at `.`, which means that this option when configured under a Rails application, might be ignored. Since Ruby is not Rails only, you can certainly specify the location path of your Ruby file that will be used to load the classes including Harmoniser::Subscriber. In contrast, if a path to a directory is passed, Harmoniser assumes that `./config/environment.rb` lives within the folder passed as option.
19
19
 
20
- The `verbose` option, when passed, sets the severity of Harmoniser logs to `debug` being able to see fine-grained details of things like RabbitMQ interactions happening or messages published into exchanges. By default, the verbosity is disabled to prevent your production environment to be flooded with unnecessary logs, however if the environment is not set to `production`, the severity of the logs is `debug` mode too.
20
+ The `verbose` option, when passed, sets the severity of Harmoniser logs to `debug` being able to see fine-grained details of things like RabbitMQ interactions happening or messages published into exchanges. By default, the verbosity is disabled to prevent your environment to be flooded with unnecessary logs.
@@ -40,11 +40,7 @@ module Harmoniser
40
40
  end
41
41
 
42
42
  def set_logger_severity
43
- @logger.level = if @options.production?
44
- @options.verbose? ? Logger::DEBUG : Logger::INFO
45
- else
46
- Logger::DEBUG
47
- end
43
+ @logger.level = @options.verbose? ? Logger::DEBUG : Logger::INFO
48
44
  end
49
45
  end
50
46
  end
@@ -5,8 +5,6 @@ module Harmoniser
5
5
  module Publisher
6
6
  class MissingExchangeDefinition < StandardError; end
7
7
  include Channelable
8
- MUTEX = Mutex.new
9
- private_constant :MUTEX
10
8
 
11
9
  module ClassMethods
12
10
  def harmoniser_publisher(exchange_name:)
@@ -20,7 +18,7 @@ module Harmoniser
20
18
  def publish(payload, opts = {})
21
19
  raise_missing_exchange_definition unless @harmoniser_exchange_definition
22
20
 
23
- MUTEX.synchronize do
21
+ const_get(:HARMONISER_PUBLISHER_MUTEX).synchronize do
24
22
  harmoniser_exchange.publish(payload, opts)
25
23
  end
26
24
  Harmoniser.logger.debug { "Message published: payload = `#{payload}`, opts = `#{opts}`" }
@@ -31,10 +29,8 @@ module Harmoniser
31
29
  private
32
30
 
33
31
  def harmoniser_exchange
34
- return @harmoniser_exchange if @harmoniser_exchange
35
-
36
32
  @harmoniser_exchange ||= Bunny::Exchange.new(
37
- Publisher.harmoniser_channel,
33
+ Publisher.create_channel,
38
34
  @harmoniser_exchange_definition.type,
39
35
  @harmoniser_exchange_definition.name,
40
36
  @harmoniser_exchange_definition.opts
@@ -48,6 +44,7 @@ module Harmoniser
48
44
 
49
45
  class << self
50
46
  def included(base)
47
+ base.const_set(:HARMONISER_PUBLISHER_MUTEX, Mutex.new)
51
48
  base.extend(ClassMethods)
52
49
  end
53
50
  end
@@ -7,8 +7,6 @@ module Harmoniser
7
7
  class MissingConsumerDefinition < StandardError; end
8
8
  include Channelable
9
9
  include Includable
10
- MUTEX = Mutex.new
11
- private_constant :MUTEX
12
10
 
13
11
  module ClassMethods
14
12
  def harmoniser_subscriber(queue_name:, consumer_tag: nil, no_ack: true, exclusive: false, arguments: {})
@@ -22,7 +20,7 @@ module Harmoniser
22
20
  end
23
21
 
24
22
  def harmoniser_subscriber_start
25
- MUTEX.synchronize do
23
+ const_get(:HARMONISER_SUBSCRIBER_MUTEX).synchronize do
26
24
  @harmoniser_consumer ||= create_consumer
27
25
  end
28
26
  end
@@ -32,10 +30,11 @@ module Harmoniser
32
30
  def create_consumer
33
31
  raise_missing_consumer_definition unless @harmoniser_consumer_definition
34
32
 
33
+ channel = Subscriber.create_channel
35
34
  consumer = Bunny::Consumer.new(
36
- Subscriber.harmoniser_channel,
35
+ channel,
37
36
  @harmoniser_consumer_definition.queue_name,
38
- @harmoniser_consumer_definition.consumer_tag || Subscriber.harmoniser_channel.generate_consumer_tag,
37
+ @harmoniser_consumer_definition.consumer_tag || channel.generate_consumer_tag,
39
38
  @harmoniser_consumer_definition.no_ack,
40
39
  @harmoniser_consumer_definition.exclusive,
41
40
  @harmoniser_consumer_definition.arguments
@@ -77,6 +76,7 @@ module Harmoniser
77
76
 
78
77
  class << self
79
78
  def included(base)
79
+ base.const_set(:HARMONISER_SUBSCRIBER_MUTEX, Mutex.new)
80
80
  base.extend(ClassMethods)
81
81
  harmoniser_register_included(base)
82
82
  end
@@ -1,3 +1,3 @@
1
1
  module Harmoniser
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  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.5.0
4
+ version: 0.6.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-20 00:00:00.000000000 Z
11
+ date: 2023-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny