sbmt-kafka_producer 2.0.0 → 2.1.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/README.md +4 -0
- data/lib/sbmt/kafka_producer/kafka_client_factory.rb +18 -3
- data/lib/sbmt/kafka_producer/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: 426c17a9e1adcdb138988d2a2b5721556f0740f37b284d805fdb7c5c230488c6
|
4
|
+
data.tar.gz: 7252b48e77ad609bbcabf45c84c8fc57de44532975e899dc2bcb96ecc696c83d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f8c5a811b2fb7b393d595b865ecdb380c6e1dbd73f9dd48805de791d86e1dff212442b141d703c32fd37f8bf1bb5587245ac37961ddc9a9185834cb539b8a35
|
7
|
+
data.tar.gz: b659ad4c35ea544d9658d1385825c5b7485990585058d25dcc515a35b3b7a9ff7c532fa1236bcffa117089a5101a41b2e2b0293a3ce204822896becd675b8bde
|
data/CHANGELOG.md
CHANGED
@@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
13
13
|
|
14
14
|
### Fixed
|
15
15
|
|
16
|
+
## [2.1.0] - 2024-03-14
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Memoize kafka clients. Add a registry with them to KafkaClientFactory.
|
21
|
+
|
16
22
|
## [2.0.0] - 2024-01-29
|
17
23
|
|
18
24
|
### Changed
|
data/README.md
CHANGED
@@ -19,6 +19,10 @@ And then execute:
|
|
19
19
|
bundle install
|
20
20
|
```
|
21
21
|
|
22
|
+
## Demo
|
23
|
+
|
24
|
+
Learn how to use this gem and how it works with Ruby on Rails at here https://github.com/SberMarket-Tech/outbox-example-apps
|
25
|
+
|
22
26
|
## Auto configuration
|
23
27
|
|
24
28
|
We recommend going through the configuration and file creation process using the following Rails generators. Each generator can be run by using the `--help` option to learn more about the available arguments.
|
@@ -3,6 +3,9 @@
|
|
3
3
|
module Sbmt
|
4
4
|
module KafkaProducer
|
5
5
|
class KafkaClientFactory
|
6
|
+
CLIENTS_REGISTRY_MUTEX = Mutex.new
|
7
|
+
CLIENTS_REGISTRY = {}
|
8
|
+
|
6
9
|
class << self
|
7
10
|
def default_client
|
8
11
|
@default_client ||= ConnectionPool::Wrapper.new do
|
@@ -15,15 +18,27 @@ module Sbmt
|
|
15
18
|
def build(kafka = {})
|
16
19
|
return default_client if kafka.empty?
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
fetch_client(kafka) do
|
22
|
+
ConnectionPool::Wrapper.new do
|
23
|
+
WaterDrop::Producer.new do |config|
|
24
|
+
configure_client(config, kafka)
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
25
30
|
private
|
26
31
|
|
32
|
+
def fetch_client(kafka)
|
33
|
+
key = Digest::SHA1.hexdigest(Marshal.dump(kafka))
|
34
|
+
return CLIENTS_REGISTRY[key] if CLIENTS_REGISTRY.key?(key)
|
35
|
+
|
36
|
+
CLIENTS_REGISTRY_MUTEX.synchronize do
|
37
|
+
return CLIENTS_REGISTRY[key] if CLIENTS_REGISTRY.key?(key)
|
38
|
+
CLIENTS_REGISTRY[key] = yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
27
42
|
def configure_client(kafka_config, kafka_options = {})
|
28
43
|
kafka_config.logger = config.logger_class.classify.constantize.new
|
29
44
|
kafka_config.kafka = config.to_kafka_options.merge(custom_kafka_config(kafka_options)).symbolize_keys
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbmt-kafka_producer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sbermarket Ruby-Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anyway_config
|