dionysus-rb 0.1.0 → 0.3.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 +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +5 -5
- data/lib/dionysus/consumer/config.rb +10 -1
- data/lib/dionysus/consumer/params_batch_processor.rb +8 -4
- data/lib/dionysus/producer/outbox.rb +4 -4
- data/lib/dionysus/version.rb +1 -1
- 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: 8297895cea885c4df1b824188297d199eed0eb00f4c52f102842e8468c02728a
|
4
|
+
data.tar.gz: b71aff2bf67cffe2a5be1e9befd29f3651a23501ee107806b7c2c6eef85f744f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ad54974b1e4956cd76f94e865c225dfe1beb2b339a29b6a594faf1671f59b4388d9a39a420788f57692e168edb1fc067e351a96d7d5883ec237f051f319eb21
|
7
|
+
data.tar.gz: 428894822478c3ed6296eb51c7440049fe39dd3ec54220abc038e1786b3f4468e48ee745cd2cadaaf7a419b9b093e79628cfb0be476602d352c6317280771685
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0]
|
4
|
+
- Allow to provide multiple message filters. `message_filter` stays for backwards compatibility and depends on `message_filters`.
|
5
|
+
|
6
|
+
## [0.2.0]
|
7
|
+
- Fix creation of outbox records when updating a record that was soft-deleted
|
8
|
+
|
3
9
|
## [0.1.0]
|
4
10
|
|
5
11
|
- Turn private gem `bookingsync-prometheus` into `dionysus-rb` and release it publicly
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -24,8 +24,8 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
24
24
|
|
25
25
|
Please read [this article first](https://www.smily.com/engineering/integration-patterns-for-distributed-architecture-how-we-use-kafka-in-smily-and-why) to understand the context how this gem was built. Also, it's just recently been made public, so some part of the docs might require clarification. If you find any section like that, don't hesitate to submit an issue.
|
26
26
|
|
27
|
-
|
28
|
-
Also, [read this article], which is an introduction to the gem.
|
27
|
+
|
28
|
+
Also, [read this article](https://www.smily.com/engineering/integration-patterns-for-distributed-architecture-intro-to-dionysus-rb), which is an introduction to the gem.
|
29
29
|
|
30
30
|
|
31
31
|
Any application can be both consumer and the producer of Karafka events, so let's take a look how to handle configuration for both scenario.
|
@@ -115,7 +115,7 @@ end
|
|
115
115
|
|
116
116
|
|
117
117
|
There are a couple of important things to understand here.
|
118
|
-
- A namespace might be used for versioning so that you can have e.g., `v3` and v4` format working at the same time and consumers consumings from different ones as they need. Namespace is a part of the topic name, in the example above the following topics are declared: `v3_accounts`, `v3_rentals`, `v3_bookings`, `v3_los_records`. Most likely you will need to create them manually in the production environement, depending the Kafka cluster configuration.
|
118
|
+
- A namespace might be used for versioning so that you can have e.g., `v3` and `v4` format working at the same time and consumers consumings from different ones as they need. Namespace is a part of the topic name, in the example above the following topics are declared: `v3_accounts`, `v3_rentals`, `v3_bookings`, `v3_los_records`. Most likely you will need to create them manually in the production environement, depending the Kafka cluster configuration.
|
119
119
|
- `topic` is a declaration of Kafka `topics`. To understand more about topics and what would be some rule of thumbs when designing them, please [read this article](https://www.smily.com/engineering/integration-patterns-for-distributed-architecture-intro-to-kafka).
|
120
120
|
- Some entities might have attributes depending on other entities (computed properties) or might need to be always published together (kind of like Domain-Driven Design Aggregate). For these cases, use `with` directive which is an equivalent of sideloading from REST APIs. E.g., Booking could have `final_price` attribute that depends on other models, like BookingsFee or BookingsTax, which contribute to that price. Publishing these items separately, e.g. first Bookings Fee first and then Booking with the changed final price might lead to inconsistency on the consumer side where `final_price` value doesn't match the value that would be obtained by summing all elements of the price. That's why all these records need to be published together. That's what `with` option is supposed to cover: `publish Booking, with: [BookingsFee, BookingsTax]`. Thanks to that declaration, any update to Booking or change its dependencies (BookingsFee, BookingsTax) such as creation/update/deletion will result in publishing `booking_updated` event.
|
121
121
|
|
@@ -1136,7 +1136,8 @@ Dionysus::Consumer.configure do |config|
|
|
1136
1136
|
config.synced_data_attribute = :synced_data # required, default: :synced_data
|
1137
1137
|
config.resolve_synced_data_hash_proc = ->(record) { record.synced_data_model.synced_data_hash } # optional, defaults to ->(record) { record.public_send(Dionysus::Consumer.configuration.synced_data_attribute).to_h }
|
1138
1138
|
config.sidekiq_queue = :default # optional, defaults to `:dionysus`
|
1139
|
-
config.message_filter = FilterIgnoringLargeMessageToAvoidOutofMemoryErrors.new(error_handler: Sentry) # not required, defaults to Dionysus::Utils::DefaultMessageFilter, which doesn't ignore any messages. It can be useful when you want to ignore some messages, e.g. some very large ones that would cause OOM error. Check the implementation of `Dionysus::Utils::DefaultMessageFilter for more details to understand what kind of arguments are available to set the condition. `error_handler` needs to implement Sentry-like interface.
|
1139
|
+
config.message_filter = FilterIgnoringLargeMessageToAvoidOutofMemoryErrors.new(error_handler: Sentry) # DEPRECATED - not required, defaults to Dionysus::Utils::DefaultMessageFilter, which doesn't ignore any messages. It can be useful when you want to ignore some messages, e.g. some very large ones that would cause OOM error. Check the implementation of `Dionysus::Utils::DefaultMessageFilter for more details to understand what kind of arguments are available to set the condition. `error_handler` needs to implement Sentry-like interface. Kept for backwards compatibility, please use `message_filters` instead.
|
1140
|
+
config.message_filters = [FilterIgnoringLargeMessageToAvoidOutofMemoryErrors.new(error_handler: Sentry)] # not required, defaults to [Dionysus::Utils::DefaultMessageFilter], which doesn't ignore any messages. It can be useful when you want to ignore some messages, e.g. some very large ones that would cause OOM error. Check the implementation of `Dionysus::Utils::DefaultMessageFilter for more details to understand what kind of arguments are available to set the condition. `error_handler` needs to implement Sentry-like interface.
|
1140
1141
|
|
1141
1142
|
# if you ever need to provide mapping:
|
1142
1143
|
|
@@ -1203,4 +1204,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Bookin
|
|
1203
1204
|
## License
|
1204
1205
|
|
1205
1206
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
1206
|
-
["NAME_OF_THE_APP"]:
|
@@ -6,7 +6,7 @@ class Dionysus::Consumer::Config
|
|
6
6
|
:instrumenter, :event_bus, :soft_delete_strategy, :soft_deleted_at_timestamp_attribute,
|
7
7
|
:synced_created_at_timestamp_attribute, :synced_updated_at_timestamp_attribute, :synced_id_attribute,
|
8
8
|
:synced_data_attribute, :consumer_base_class, :retry_provider, :resolve_synced_data_hash_proc, :sidekiq_queue,
|
9
|
-
:
|
9
|
+
:message_filters
|
10
10
|
|
11
11
|
def self.default_sidekiq_queue
|
12
12
|
:dionysus
|
@@ -94,4 +94,13 @@ class Dionysus::Consumer::Config
|
|
94
94
|
@message_filter || Dionysus::Utils::DefaultMessageFilter.new(error_handler:
|
95
95
|
Dionysus::Utils::NullErrorHandler)
|
96
96
|
end
|
97
|
+
|
98
|
+
def message_filter=(val)
|
99
|
+
@message_filter = val
|
100
|
+
self.message_filters = [val]
|
101
|
+
end
|
102
|
+
|
103
|
+
def message_filters
|
104
|
+
@message_filters || Array.wrap(message_filter)
|
105
|
+
end
|
97
106
|
end
|
@@ -27,8 +27,9 @@ class Dionysus::Consumer::ParamsBatchProcessor
|
|
27
27
|
transformed_data = Dionysus::Consumer::Deserializer.new(data).deserialize
|
28
28
|
end
|
29
29
|
|
30
|
-
if
|
31
|
-
notify_about_ignored_message(topic: topic, message: message,
|
30
|
+
if (applicable_message_filter = find_applicable_message_filter(topic, message, transformed_data))
|
31
|
+
applicable_message_filter.notify_about_ignored_message(topic: topic, message: message,
|
32
|
+
transformed_data: transformed_data)
|
32
33
|
next
|
33
34
|
end
|
34
35
|
|
@@ -50,8 +51,11 @@ class Dionysus::Consumer::ParamsBatchProcessor
|
|
50
51
|
|
51
52
|
private
|
52
53
|
|
53
|
-
delegate :
|
54
|
-
|
54
|
+
delegate :message_filters, to: :config
|
55
|
+
|
56
|
+
def find_applicable_message_filter(topic, message, transformed_data)
|
57
|
+
message_filters.find { |f| f.ignore_message?(topic: topic, message: message, transformed_data: transformed_data) }
|
58
|
+
end
|
55
59
|
|
56
60
|
def instrument(label, options = {}, &block)
|
57
61
|
config.instrumenter.instrument(label, options, &block)
|
@@ -82,10 +82,10 @@ class Dionysus::Producer::Outbox
|
|
82
82
|
def event_type_for_update_of_soft_deletable_record_for_soft_delete_state_change(publishable)
|
83
83
|
if publishable.previous_changes_uncanceled?
|
84
84
|
:created
|
85
|
-
elsif publishable.previous_changes_canceled?
|
85
|
+
elsif publishable.previous_changes_canceled? || publishable.previous_changes_still_canceled?
|
86
86
|
:destroyed
|
87
|
-
elsif publishable.
|
88
|
-
|
87
|
+
elsif publishable.previous_changed_still_visible?
|
88
|
+
raise "that should never happen: a cannot be still visible when it was soft-deleted"
|
89
89
|
else
|
90
90
|
raise "that should never happen"
|
91
91
|
end
|
@@ -95,7 +95,7 @@ class Dionysus::Producer::Outbox
|
|
95
95
|
if publishable.visible? || (publishable.soft_deleted? && publishable.dionysus_publish_updates_after_soft_delete?)
|
96
96
|
:updated
|
97
97
|
elsif publishable.soft_deleted?
|
98
|
-
nil
|
98
|
+
nil # deliberately not returning any event because the record is configured as such
|
99
99
|
else
|
100
100
|
raise "that should never happen"
|
101
101
|
end
|
data/lib/dionysus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dionysus-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Galanciak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|