sbmt-kafka_producer 2.0.0 → 2.2.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: 3b6c10d4e49a462afad448f607d1d9c202b59a7b70661ef17cf7ec8dd4d8112e
4
- data.tar.gz: 4cf15927ca33194dc5639afcf7967b3965ac817ad8813380e33f7dc003aa11d0
3
+ metadata.gz: 4f2c9bec545e5dd939135a388d69acd38c4adfbc65c5d0f9db1cfc94d5431290
4
+ data.tar.gz: 77d7376225e878c89499bb19bea8cd87230b247a4b238856fc2724101872a9f8
5
5
  SHA512:
6
- metadata.gz: 467ccc822998a5a9bb174557b6a72be74855060cb5e24e3097efb9ac9be746adfede6c4c77721e637ae6b14db4dc8983c7b76a23c6127016345f3f7fdcf1f681
7
- data.tar.gz: bd1df75213ff393acf379fe4d3bbf013747af8f193a0970effbff0782e6c7dd1adeb8cd8cec4704cebb6fc214a1631dc330a679d77ca83c786067786adda329f
6
+ metadata.gz: 9fb93062edacf5150ad961b79031acdbc4adcf7cf823563014b041bd69e78cb988caf46b107b5f27c6fb0eafdc8d460da2b88c3279786aedf7534a3ad4febfb2
7
+ data.tar.gz: 11cc83bda4221bac3b65be54606d75dbb2c1acc7e55d6cb41012207ad78fc6715d1bdc3fc8da58ff1bd45d339bdfc2a77167bc7af7115c005d0aa9dd77e536ae
data/CHANGELOG.md CHANGED
@@ -13,6 +13,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
13
13
 
14
14
  ### Fixed
15
15
 
16
+ ## [2.2.0] - 2024-04-12
17
+
18
+ ### Changed
19
+
20
+ - Add logs with `offset`.
21
+
22
+ ## [2.1.0] - 2024-03-14
23
+
24
+ ### Changed
25
+
26
+ - Memoize kafka clients. Add a registry with them to KafkaClientFactory.
27
+
16
28
  ## [2.0.0] - 2024-01-29
17
29
 
18
30
  ### 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.
@@ -9,9 +9,10 @@ module Sbmt
9
9
  option :topic
10
10
 
11
11
  def sync_publish!(payload, options = {})
12
- around_publish do
12
+ report = around_publish do
13
13
  client.produce_sync(payload: payload, **options.merge(topic: topic))
14
14
  end
15
+ log_success(report)
15
16
  true
16
17
  end
17
18
 
@@ -81,6 +82,10 @@ module Sbmt
81
82
  ErrorTracker.error(error)
82
83
  end
83
84
 
85
+ def log_success(report)
86
+ logger.info "Message has been successfully sent to Kafka - topic: #{report.topic_name}, partition: #{report.partition}, offset: #{report.offset}"
87
+ end
88
+
84
89
  def format_exception_error(error)
85
90
  text = "#{format_exception_error(error.cause)}. " if with_cause?(error)
86
91
 
@@ -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
- ConnectionPool::Wrapper.new do
19
- WaterDrop::Producer.new do |config|
20
- configure_client(config, kafka)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sbmt
4
4
  module KafkaProducer
5
- VERSION = "2.0.0"
5
+ VERSION = "2.2.0"
6
6
  end
7
7
  end
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.0.0
4
+ version: 2.2.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-02-27 00:00:00.000000000 Z
11
+ date: 2024-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config