sbmt-kafka_consumer 3.7.1 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 529772cc93b9d4d6cae27acefde83b6c14c963bc851e58a86d89d4f9c4e2c713
4
- data.tar.gz: 9302cd5e4a6986e269487fa222bc3b224570971565a5522e64c9038a5ae89464
3
+ metadata.gz: f27dbc3bc5e2ddf818b77186d454f94a0d0368fbb44320e226762a1d8a354600
4
+ data.tar.gz: 7b2e007ee9cafad443a67b8be62671f31c2963b214596e89684ce39569514b5c
5
5
  SHA512:
6
- metadata.gz: 15341d8328b6442e648aa07b517c5fa49cad45a52b972d1e4a9c3512323d55d32b771701835d76aa9daa5832a2e9a6fbcd1f245e1808210fd5a006ef7ea91ba1
7
- data.tar.gz: 03f3aabd3caf71729ce0293e73d8ca087d5d9fd71454ac87b9d852d537e9922fdd6f6591e43835d08906ab1b601d99d9daa5ee29d20c90a5162df94cf72fb174
6
+ metadata.gz: c0bfb55730305e95b799c9e3674902d272e89ce8425a8067ce70abaad3142d09d06c2af5a52025215e4004f08b16b570cbd173cfcdcaf4234d44f1ade99e2803
7
+ data.tar.gz: a1fa3f14330a7502ad187e261c0d580f71402752faca0b251957ea139ad3ebe687097923192be1aefaeea68609716ec82d02ca2e8343bc2f1212005c940f4f21
data/.rubocop.yml CHANGED
@@ -28,6 +28,14 @@ RSpec/VerifiedDoubles:
28
28
  Exclude:
29
29
  - spec/**/*_spec.rb
30
30
 
31
+ RSpec/SpecFilePathFormat:
32
+ Exclude:
33
+ - spec/generators/**/*
34
+
35
+ RSpec/InstanceVariable:
36
+ Exclude:
37
+ - spec/generators/**/*
38
+
31
39
  Style/SingleLineMethods:
32
40
  Enabled: false
33
41
 
data/Appraisals CHANGED
@@ -3,7 +3,7 @@
3
3
  # See compatibility table at https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
4
4
 
5
5
  versions_map = {
6
- "6.1" => %w[2.7 3.0],
6
+ "6.1" => %w[3.0],
7
7
  "7.0" => %w[3.1],
8
8
  "7.1" => %w[3.2],
9
9
  "7.2" => %w[3.3],
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
+ ## [3.8.0] - 2026-03-03
17
+
18
+ ### Added
19
+
20
+ - `kafka_consumer:regexp_consumer` generator for injecting a regexp-based consumer group entry into `config/kafka_consumer.yml`; offers to run `kafka_consumer:install` if the config file is missing
21
+
16
22
  ## [3.7.1] - 2026-02-17
17
23
 
18
24
  ### Fixed
data/Gemfile CHANGED
@@ -3,6 +3,3 @@
3
3
  source ENV.fetch("RUBYGEMS_PUBLIC_SOURCE", "https://rubygems.org/")
4
4
 
5
5
  gemspec
6
-
7
- # FIXME: remove this after drop support for Ruby 2.7
8
- gem "ffi", "< 1.17"
data/README.md CHANGED
@@ -53,6 +53,50 @@ To generate an Inbox consumer for use with gem [sbmt-outbox](https://github.com/
53
53
  rails g kafka_consumer:inbox_consumer MaybeNamespaced::Name some-consumer-group some-topic
54
54
  ```
55
55
 
56
+ ### Regexp consumer
57
+
58
+ To generate a regexp-topic consumer:
59
+
60
+ ```shell
61
+ rails g kafka_consumer:regexp_consumer GROUP_KEY CONSUMER_KLASS TOPIC_REGEXP --env-prefix ENV_PREFIX
62
+ ```
63
+
64
+ Where:
65
+ - `GROUP_KEY` — YAML key for the consumer group (e.g. `order`)
66
+ - `CONSUMER_KLASS` — consumer class name (e.g. `MyApp::OrderConsumer`)
67
+ - `TOPIC_REGEXP` — topic regexp (e.g. `'my\.app\.order(\.\d+)?$'`)
68
+ - `--env-prefix` (required) — prefix for the `ENV_PREFIX_CONSUMER_GROUP_NAME` and `ENV_PREFIX_TOPIC_REGEXP` environment variables
69
+ - `--init-attrs key:value ...` — optional consumer `init_attrs` as `key:value` pairs; boolean values (`true`/`false`) are emitted unquoted
70
+ - `--deserializer-klass` — optional deserializer class; omit to skip the `deserializer:` section
71
+
72
+ If `config/kafka_consumer.yml` does not exist, the generator will offer to run `kafka_consumer:install` first.
73
+
74
+ Examples:
75
+
76
+ ```shell
77
+ # Consumer with init_attrs
78
+ rails g kafka_consumer:regexp_consumer order \
79
+ "MyApp::OrderConsumer" \
80
+ 'my\.app\.order(\.\d+)?$' \
81
+ --env-prefix MY_APP_ORDER \
82
+ --init-attrs inbox_item:OrderInboxItem
83
+
84
+ # Consumer with deserializer
85
+ rails g kafka_consumer:regexp_consumer events \
86
+ "MyApp::EventsConsumer" \
87
+ 'my\.app\.events(\.\d+)?$' \
88
+ --env-prefix MY_APP_EVENTS \
89
+ --deserializer-klass "Sbmt::KafkaConsumer::Serialization::JsonDeserializer"
90
+
91
+ # Consumer with both
92
+ rails g kafka_consumer:regexp_consumer order_init \
93
+ "MyApp::OrderInitConsumer" \
94
+ 'my\.app\.order\.init(\.\d+)?$' \
95
+ --env-prefix MY_APP_ORDER_INIT \
96
+ --init-attrs envelope_schema:my.envelope data_schema:my.app.order.init skip_on_error:true \
97
+ --deserializer-klass "Sbmt::KafkaConsumer::Serialization::JsonDeserializer"
98
+ ```
99
+
56
100
  ## Manual configuration
57
101
 
58
102
  The `config/kafka_consumer.yml` file is a main configuration for the gem.
@@ -0,0 +1,29 @@
1
+ Description:
2
+ Injects a regexp-based consumer group entry into config/kafka_consumer.yml.
3
+ If kafka_consumer.yml does not exist, offers to run kafka_consumer:install first.
4
+
5
+ Required positional args: GROUP_KEY, CONSUMER_KLASS, TOPIC_REGEXP
6
+ Required option: --env-prefix
7
+
8
+ Example:
9
+ # Inbox consumer with init_attrs (no deserializer)
10
+ bin/rails generate kafka_consumer:regexp_consumer order \
11
+ "Ecom::EventStreaming::Kafka::RegularEventsInboxConsumer" \
12
+ 'seeker\.paas-stand\.event-streaming\.order(\.\d+)?$' \
13
+ --env-prefix ES_ORDER \
14
+ --init-attrs inbox_item:EsOrderInboxItem
15
+
16
+ # Consumer with deserializer (no init_attrs)
17
+ bin/rails generate kafka_consumer:regexp_consumer init_exports \
18
+ "Ecom::EventStreaming::Kafka::ControlRequestsConsumer" \
19
+ 'yc\.seeker\.paas-stand\.event-streaming\.control\.in(\.\d+)?' \
20
+ --env-prefix ES_CONTROL_REQUESTS \
21
+ --deserializer-klass "Sbmt::KafkaConsumer::Serialization::JsonDeserializer"
22
+
23
+ # Consumer with both init_attrs (including boolean) and deserializer
24
+ bin/rails generate kafka_consumer:regexp_consumer seeker_init_exports \
25
+ "SeekerInitEventsConsumer" \
26
+ 'seeker\.paas-stand\.event-streaming\.order\.init(\.\d+)?$' \
27
+ --env-prefix ES_SEEKER_INIT_EXPORTS \
28
+ --init-attrs envelope_schema:cloud-events.init.envelope data_schema:seeker.paas-stand.event-streaming.order.init skip_on_error:true \
29
+ --deserializer-klass "Sbmt::KafkaConsumer::Serialization::JsonDeserializer"
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/named_base"
4
+ require "generators/kafka_consumer/concerns/configuration"
5
+
6
+ module KafkaConsumer
7
+ module Generators
8
+ class RegexpConsumerGenerator < Rails::Generators::NamedBase
9
+ include Concerns::Configuration
10
+
11
+ source_root File.expand_path("templates", __dir__)
12
+
13
+ desc "Injects a regexp-based consumer group entry into config/kafka_consumer.yml"
14
+
15
+ argument :consumer_klass, type: :string,
16
+ desc: "Consumer class name (e.g. Ecom::EventStreaming::Kafka::RegularEventsInboxConsumer)"
17
+
18
+ argument :topic_regexp, type: :string,
19
+ desc: "Topic regexp value (e.g. 'seeker\\.paas-stand\\.event-streaming\\.order(\\.\\d+)?\\$')"
20
+
21
+ class_option :env_prefix, type: :string, required: true,
22
+ desc: "ENV variable prefix for CONSUMER_GROUP_NAME and TOPIC_REGEXP (e.g. ES_ORDER)"
23
+
24
+ class_option :init_attrs, type: :hash, default: {},
25
+ banner: "key:value key:value",
26
+ desc: "Consumer init_attrs as key:value pairs (e.g. inbox_item:Foo skip_on_error:true)"
27
+
28
+ class_option :deserializer_klass, type: :string, default: nil,
29
+ desc: "Deserializer class (omit to skip deserializer section)"
30
+
31
+ def inject_consumer_group
32
+ check_config_file!
33
+ insert_into_file CONFIG_PATH, consumer_group_entry, after: "consumer_groups:\n"
34
+ end
35
+
36
+ private
37
+
38
+ # Override to resolve path relative to destination_root (works in both
39
+ # app context and generator tests with a tmpdir destination_root).
40
+ def check_config_file!
41
+ return if File.exist?(File.join(destination_root, CONFIG_PATH))
42
+
43
+ generator_name = "kafka_consumer:install"
44
+ answer = ask("The file #{CONFIG_PATH} does not appear to exist. Would you like to generate it? [Yn]")
45
+ if (answer.presence || "y").casecmp("y").zero?
46
+ generate generator_name
47
+ else
48
+ raise Rails::Generators::Error,
49
+ "Please generate #{CONFIG_PATH} by running `bin/rails g #{generator_name}` or add this file manually."
50
+ end
51
+ end
52
+
53
+ def group_key
54
+ file_name
55
+ end
56
+
57
+ def env_prefix
58
+ options[:env_prefix]
59
+ end
60
+
61
+ def init_attrs
62
+ options[:init_attrs]
63
+ end
64
+
65
+ def deserializer_klass
66
+ options[:deserializer_klass]
67
+ end
68
+
69
+ def format_attr_value(value)
70
+ (value == "true" || value == "false") ? value : "\"#{value}\""
71
+ end
72
+
73
+ def consumer_group_entry
74
+ template_path = File.join(self.class.source_root, "consumer_group.yml.erb")
75
+ ERB.new(File.read(template_path), trim_mode: "%-").result(binding)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,16 @@
1
+ '<%= group_key %>':
2
+ name: <%%= ENV.fetch("<%= env_prefix %>_CONSUMER_GROUP_NAME", "<%= group_key %>") %><%%= ENV.fetch("CONSUMER_GROUP_SUFFIX", "") %>
3
+ topics:
4
+ - regexp: <%%= ENV.fetch("<%= env_prefix %>_TOPIC_REGEXP", '<%= topic_regexp %>') %>
5
+ consumer:
6
+ klass: "<%= consumer_klass %>"
7
+ <%- unless init_attrs.empty? -%>
8
+ init_attrs:
9
+ <%- init_attrs.each do |key, value| -%>
10
+ <%= key %>: <%= format_attr_value(value) %>
11
+ <%- end -%>
12
+ <%- end -%>
13
+ <%- if deserializer_klass -%>
14
+ deserializer:
15
+ klass: "<%= deserializer_klass %>"
16
+ <%- end -%>
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sbmt
4
4
  module KafkaConsumer
5
- VERSION = "3.7.1"
5
+ VERSION = "3.8.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbmt-kafka_consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuper Ruby-Platform Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-02-17 00:00:00.000000000 Z
11
+ date: 2026-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -492,6 +492,9 @@ files:
492
492
  - lib/generators/kafka_consumer/install/install_generator.rb
493
493
  - lib/generators/kafka_consumer/install/templates/Kafkafile
494
494
  - lib/generators/kafka_consumer/install/templates/kafka_consumer.yml
495
+ - lib/generators/kafka_consumer/regexp_consumer/USAGE
496
+ - lib/generators/kafka_consumer/regexp_consumer/regexp_consumer_generator.rb
497
+ - lib/generators/kafka_consumer/regexp_consumer/templates/consumer_group.yml.erb
495
498
  - lib/sbmt/kafka_consumer.rb
496
499
  - lib/sbmt/kafka_consumer/app_initializer.rb
497
500
  - lib/sbmt/kafka_consumer/base_consumer.rb
@@ -570,7 +573,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
570
573
  - !ruby/object:Gem::Version
571
574
  version: '0'
572
575
  requirements: []
573
- rubygems_version: 3.3.7
576
+ rubygems_version: 3.2.33
574
577
  signing_key:
575
578
  specification_version: 4
576
579
  summary: Ruby gem for consuming Kafka messages