karafka 1.2.11 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +3 -0
- data/{.coditsu.yml → .coditsu/ci.yml} +1 -1
- data/.console_irbrc +1 -3
- data/.github/FUNDING.yml +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +50 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +8 -21
- data/CHANGELOG.md +86 -14
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +2 -5
- data/Gemfile.lock +76 -61
- data/README.md +10 -11
- data/bin/karafka +1 -1
- data/certs/mensfeld.pem +25 -0
- data/config/errors.yml +38 -5
- data/karafka.gemspec +14 -12
- data/lib/karafka.rb +7 -15
- data/lib/karafka/app.rb +14 -6
- data/lib/karafka/attributes_map.rb +4 -5
- data/lib/karafka/base_consumer.rb +19 -30
- data/lib/karafka/base_responder.rb +45 -27
- data/lib/karafka/cli.rb +1 -1
- data/lib/karafka/cli/console.rb +11 -9
- data/lib/karafka/cli/flow.rb +0 -1
- data/lib/karafka/cli/info.rb +3 -1
- data/lib/karafka/cli/install.rb +30 -6
- data/lib/karafka/cli/server.rb +11 -6
- data/lib/karafka/code_reloader.rb +67 -0
- data/lib/karafka/connection/api_adapter.rb +11 -4
- data/lib/karafka/connection/batch_delegator.rb +51 -0
- data/lib/karafka/connection/builder.rb +1 -1
- data/lib/karafka/connection/client.rb +30 -20
- data/lib/karafka/connection/listener.rb +24 -13
- data/lib/karafka/connection/message_delegator.rb +36 -0
- data/lib/karafka/consumers/callbacks.rb +32 -15
- data/lib/karafka/consumers/includer.rb +30 -18
- data/lib/karafka/consumers/metadata.rb +10 -0
- data/lib/karafka/consumers/responders.rb +2 -2
- data/lib/karafka/contracts.rb +10 -0
- data/lib/karafka/contracts/config.rb +21 -0
- data/lib/karafka/contracts/consumer_group.rb +206 -0
- data/lib/karafka/contracts/consumer_group_topic.rb +19 -0
- data/lib/karafka/contracts/responder_usage.rb +54 -0
- data/lib/karafka/contracts/server_cli_options.rb +29 -0
- data/lib/karafka/errors.rb +17 -16
- data/lib/karafka/fetcher.rb +28 -30
- data/lib/karafka/helpers/class_matcher.rb +12 -2
- data/lib/karafka/helpers/config_retriever.rb +1 -1
- data/lib/karafka/helpers/inflector.rb +26 -0
- data/lib/karafka/helpers/multi_delegator.rb +0 -1
- data/lib/karafka/instrumentation/logger.rb +9 -6
- data/lib/karafka/instrumentation/monitor.rb +15 -9
- data/lib/karafka/instrumentation/proctitle_listener.rb +36 -0
- data/lib/karafka/instrumentation/stdout_listener.rb +138 -0
- data/lib/karafka/params/builders/metadata.rb +33 -0
- data/lib/karafka/params/builders/params.rb +36 -0
- data/lib/karafka/params/builders/params_batch.rb +25 -0
- data/lib/karafka/params/metadata.rb +35 -0
- data/lib/karafka/params/params.rb +68 -0
- data/lib/karafka/params/params_batch.rb +35 -20
- data/lib/karafka/patches/ruby_kafka.rb +21 -8
- data/lib/karafka/persistence/client.rb +15 -11
- data/lib/karafka/persistence/{consumer.rb → consumers.rb} +20 -13
- data/lib/karafka/persistence/topics.rb +48 -0
- data/lib/karafka/process.rb +0 -2
- data/lib/karafka/responders/builder.rb +1 -1
- data/lib/karafka/responders/topic.rb +6 -8
- data/lib/karafka/routing/builder.rb +36 -8
- data/lib/karafka/routing/consumer_group.rb +1 -1
- data/lib/karafka/routing/consumer_mapper.rb +9 -9
- data/lib/karafka/routing/proxy.rb +10 -1
- data/lib/karafka/routing/topic.rb +5 -3
- data/lib/karafka/routing/topic_mapper.rb +16 -18
- data/lib/karafka/serialization/json/deserializer.rb +27 -0
- data/lib/karafka/serialization/json/serializer.rb +31 -0
- data/lib/karafka/server.rb +25 -27
- data/lib/karafka/setup/config.rb +65 -37
- data/lib/karafka/setup/configurators/water_drop.rb +7 -3
- data/lib/karafka/setup/dsl.rb +0 -1
- data/lib/karafka/status.rb +7 -3
- data/lib/karafka/templates/{application_consumer.rb.example → application_consumer.rb.erb} +2 -1
- data/lib/karafka/templates/{application_responder.rb.example → application_responder.rb.erb} +0 -0
- data/lib/karafka/templates/karafka.rb.erb +92 -0
- data/lib/karafka/version.rb +1 -1
- metadata +90 -57
- metadata.gz.sig +0 -0
- data/lib/karafka/callbacks.rb +0 -30
- data/lib/karafka/callbacks/config.rb +0 -22
- data/lib/karafka/callbacks/dsl.rb +0 -16
- data/lib/karafka/connection/delegator.rb +0 -46
- data/lib/karafka/instrumentation/listener.rb +0 -112
- data/lib/karafka/loader.rb +0 -28
- data/lib/karafka/params/dsl.rb +0 -158
- data/lib/karafka/parsers/json.rb +0 -38
- data/lib/karafka/patches/dry_configurable.rb +0 -33
- data/lib/karafka/persistence/topic.rb +0 -29
- data/lib/karafka/schemas/config.rb +0 -24
- data/lib/karafka/schemas/consumer_group.rb +0 -78
- data/lib/karafka/schemas/consumer_group_topic.rb +0 -18
- data/lib/karafka/schemas/responder_usage.rb +0 -39
- data/lib/karafka/schemas/server_cli_options.rb +0 -43
- data/lib/karafka/setup/configurators/base.rb +0 -29
- data/lib/karafka/setup/configurators/params.rb +0 -25
- data/lib/karafka/templates/karafka.rb.example +0 -54
data/lib/karafka/loader.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
# Loader for requiring all the files in a proper order
|
5
|
-
module Loader
|
6
|
-
# Order in which we want to load app files
|
7
|
-
DIRS = %w[
|
8
|
-
lib
|
9
|
-
app
|
10
|
-
].freeze
|
11
|
-
|
12
|
-
# Will load files in a proper order (based on DIRS)
|
13
|
-
# @param [String] root path from which we want to start
|
14
|
-
def self.load(root)
|
15
|
-
DIRS.each do |dir|
|
16
|
-
path = File.join(root, dir)
|
17
|
-
next unless File.exist?(path)
|
18
|
-
load!(path)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Requires all the ruby files from one path in a proper order
|
23
|
-
# @param path [String] path (dir) from which we want to load ruby files in a proper order
|
24
|
-
def self.load!(path)
|
25
|
-
require_all(path)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/karafka/params/dsl.rb
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
# Params namespace encapsulating all the logic that is directly related to params handling
|
5
|
-
module Params
|
6
|
-
# Dsl for Karafka params. We don't provide the params class here as we want to allow users to
|
7
|
-
# use either hash (default) or Rails hash with indifferent access as a base for their params
|
8
|
-
#
|
9
|
-
# We do that because both of them have their own advantages and we don't want to enforce users
|
10
|
-
# to handle things differently if they already use any of those
|
11
|
-
#
|
12
|
-
# It provides lazy loading not only until the first usage, but also allows us to skip
|
13
|
-
# using parser until we execute our logic. That way we can operate with
|
14
|
-
# heavy-parsing data without slowing down the whole application.
|
15
|
-
module Dsl
|
16
|
-
# Params keys that are "our" and internal. We use this list for additional backends
|
17
|
-
# that somehow operatae on those keys
|
18
|
-
SYSTEM_KEYS = %w[
|
19
|
-
parser
|
20
|
-
value
|
21
|
-
partition
|
22
|
-
offset
|
23
|
-
key
|
24
|
-
create_time
|
25
|
-
receive_time
|
26
|
-
topic
|
27
|
-
parsed
|
28
|
-
].freeze
|
29
|
-
|
30
|
-
# Params attributes that should be available via a method call invocation for Kafka
|
31
|
-
# client compatibility.
|
32
|
-
# Kafka passes internally Kafka::FetchedMessage object and the ruby-kafka consumer
|
33
|
-
# uses those fields via method calls, so in order to be able to pass there our params
|
34
|
-
# objects, have to have same api.
|
35
|
-
METHOD_ATTRIBUTES = %w[
|
36
|
-
topic
|
37
|
-
partition
|
38
|
-
offset
|
39
|
-
key
|
40
|
-
create_time
|
41
|
-
receive_time
|
42
|
-
].freeze
|
43
|
-
|
44
|
-
private_constant :METHOD_ATTRIBUTES
|
45
|
-
|
46
|
-
# Class methods required by params to work
|
47
|
-
module ClassMethods
|
48
|
-
# We allow building instances only via the #build method
|
49
|
-
|
50
|
-
# @param message [Kafka::FetchedMessage, Hash] message that we get out of Kafka
|
51
|
-
# in case of building params inside main Karafka process in
|
52
|
-
# Karafka::Connection::Consumer, or a hash when we retrieve data that is already parsed
|
53
|
-
# @param parser [Class] parser class that we will use to unparse data
|
54
|
-
# @return [Karafka::Params::Params] Karafka params object not yet used parser for
|
55
|
-
# retrieving data that we've got from Kafka
|
56
|
-
# @example Build params instance from a hash
|
57
|
-
# Karafka::Params::Params.build({ key: 'value' }) #=> params object
|
58
|
-
# @example Build params instance from a Kafka::FetchedMessage object
|
59
|
-
# Karafka::Params::Params.build(message) #=> params object
|
60
|
-
def build(message, parser)
|
61
|
-
instance = new
|
62
|
-
instance['parser'] = parser
|
63
|
-
|
64
|
-
# Non kafka fetched message can happen when we interchange data with an
|
65
|
-
# additional backend
|
66
|
-
if message.is_a?(Kafka::FetchedMessage)
|
67
|
-
instance.send(
|
68
|
-
:merge!,
|
69
|
-
'value' => message.value,
|
70
|
-
'partition' => message.partition,
|
71
|
-
'offset' => message.offset,
|
72
|
-
'key' => message.key,
|
73
|
-
'create_time' => message.create_time,
|
74
|
-
'receive_time' => Time.now,
|
75
|
-
# When we get raw messages, they might have a topic, that was modified by a
|
76
|
-
# topic mapper. We need to "reverse" this change and map back to the non-modified
|
77
|
-
# format, so our internal flow is not corrupted with the mapping
|
78
|
-
'topic' => Karafka::App.config.topic_mapper.incoming(message.topic)
|
79
|
-
)
|
80
|
-
else
|
81
|
-
instance.send(:merge!, message)
|
82
|
-
end
|
83
|
-
|
84
|
-
instance
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# @return [Karafka::Params::Params] this will trigger parser execution. If we decide to
|
89
|
-
# retrieve data, parser will be executed to parse data. Output of parsing will be merged
|
90
|
-
# to the current object. This object will be also marked as already parsed, so we won't
|
91
|
-
# parse it again.
|
92
|
-
def retrieve!
|
93
|
-
return self if self['parsed']
|
94
|
-
self['parsed'] = true
|
95
|
-
|
96
|
-
parsed_data = parse(self['value'])
|
97
|
-
delete('value')
|
98
|
-
merge!(parsed_data)
|
99
|
-
end
|
100
|
-
|
101
|
-
# Includes and extends the base params klass with everything that is needed by Karafka to
|
102
|
-
# fully work in any conditions.
|
103
|
-
# @param params_klass [Karafka::Params::Params] initialized params class that we will
|
104
|
-
# use for a given Karafka process
|
105
|
-
def self.included(params_klass)
|
106
|
-
params_klass.extend(Dsl::ClassMethods)
|
107
|
-
|
108
|
-
METHOD_ATTRIBUTES.each do |attr|
|
109
|
-
# Defines a method call accessor to a particular hash field.
|
110
|
-
# @note Won't work for complex key names that contain spaces, etc
|
111
|
-
# @param key [Symbol] name of a field that we want to retrieve with a method call
|
112
|
-
# @example
|
113
|
-
# key_attr_reader :example
|
114
|
-
# params.example #=> 'my example value'
|
115
|
-
params_klass.send :define_method, attr do
|
116
|
-
self[attr]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
params_klass.send :private, :merge!
|
121
|
-
params_klass.send :private, :parse
|
122
|
-
end
|
123
|
-
|
124
|
-
private
|
125
|
-
|
126
|
-
# Overwritten merge! method - it behaves differently for keys that are the same in our hash
|
127
|
-
# and in a other_hash - it will not replace keys that are the same in our hash
|
128
|
-
# and in the other one. This protects some important Karafka params keys that cannot be
|
129
|
-
# replaced with custom values from incoming Kafka message
|
130
|
-
# @param other_hash [Hash] hash that we want to merge into current
|
131
|
-
# @return [Karafka::Params::Params] our parameters hash with merged values
|
132
|
-
# @example Merge with hash without same keys
|
133
|
-
# new(a: 1, b: 2).merge!(c: 3) #=> { a: 1, b: 2, c: 3 }
|
134
|
-
# @example Merge with hash with same keys (symbol based)
|
135
|
-
# new(a: 1).merge!(a: 2) #=> { a: 1 }
|
136
|
-
# @example Merge with hash with same keys (string based)
|
137
|
-
# new(a: 1).merge!('a' => 2) #=> { a: 1 }
|
138
|
-
# @example Merge with hash with same keys (current string based)
|
139
|
-
# new('a' => 1).merge!(a: 2) #=> { a: 1 }
|
140
|
-
def merge!(other_hash)
|
141
|
-
super(other_hash) { |_key, base_value, _new_value| base_value }
|
142
|
-
end
|
143
|
-
|
144
|
-
# @param value [String] Raw data that we want to parse using consumer parser
|
145
|
-
# @note If something goes wrong, it will return raw data in a hash with a message key
|
146
|
-
# @return [Hash] parsed data or a hash with message key containing raw data if something
|
147
|
-
# went wrong during parsing
|
148
|
-
def parse(value)
|
149
|
-
Karafka.monitor.instrument('params.params.parse', caller: self) do
|
150
|
-
self['parser'].parse(value)
|
151
|
-
end
|
152
|
-
rescue ::Karafka::Errors::ParserError => e
|
153
|
-
Karafka.monitor.instrument('params.params.parse.error', caller: self, error: e)
|
154
|
-
raise e
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
data/lib/karafka/parsers/json.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
# Module for all supported by default parsers for incoming/outgoing data
|
5
|
-
module Parsers
|
6
|
-
# Default Karafka Json parser for serializing and deserializing data
|
7
|
-
class Json
|
8
|
-
# @param content [String] content based on which we want to get our hash
|
9
|
-
# @return [Hash] hash with parsed JSON data
|
10
|
-
# @example
|
11
|
-
# Json.parse("{\"a\":1}") #=> { 'a' => 1 }
|
12
|
-
def self.parse(content)
|
13
|
-
::MultiJson.load(content)
|
14
|
-
rescue ::MultiJson::ParseError => e
|
15
|
-
raise ::Karafka::Errors::ParserError, e
|
16
|
-
end
|
17
|
-
|
18
|
-
# @param content [Object] any object that we want to convert to a json string
|
19
|
-
# @return [String] Valid JSON string containing serialized data
|
20
|
-
# @raise [Karafka::Errors::ParserError] raised when we don't have a way to parse
|
21
|
-
# given content to a json string format
|
22
|
-
# @note When string is passed to this method, we assume that it is already a json
|
23
|
-
# string and we don't serialize it again. This allows us to serialize data before
|
24
|
-
# it is being forwarded to a parser if we want to have a custom (not that simple)
|
25
|
-
# json serialization
|
26
|
-
#
|
27
|
-
# @example From an ActiveRecord object
|
28
|
-
# Json.generate(Repository.first) #=> "{\"repository\":{\"id\":\"04b504e0\"}}"
|
29
|
-
# @example From a string (no changes)
|
30
|
-
# Json.generate("{\"a\":1}") #=> "{\"a\":1}"
|
31
|
-
def self.generate(content)
|
32
|
-
return content if content.is_a?(String)
|
33
|
-
return content.to_json if content.respond_to?(:to_json)
|
34
|
-
raise Karafka::Errors::ParserError, content
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
# Namespace for patches of external gems/libraries
|
5
|
-
module Patches
|
6
|
-
# Patch that will allow to use proc based lazy evaluated settings with Dry Configurable
|
7
|
-
# @see https://github.com/dry-rb/dry-configurable/blob/master/lib/dry/configurable.rb
|
8
|
-
module DryConfigurable
|
9
|
-
# We overwrite ::Dry::Configurable::Config to change on proc behaviour
|
10
|
-
# Unfortunately it does not provide an on call proc evaluation, so
|
11
|
-
# this feature had to be added here on demand/
|
12
|
-
# @param args Any arguments that DryConfigurable::Config accepts
|
13
|
-
def define!(*args)
|
14
|
-
super.tap { @config.each_key(&method(:rebuild)) }
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
# Method that rebuilds a given accessor, so when it consists a proc value, it will
|
20
|
-
# evaluate it upon return for blocks that don't require any arguments, otherwise
|
21
|
-
# it will return the block
|
22
|
-
# @param method_name [Symbol] name of an accessor that we want to rebuild
|
23
|
-
def rebuild(method_name)
|
24
|
-
define_singleton_method method_name do
|
25
|
-
value = super()
|
26
|
-
return value unless value.is_a?(Proc)
|
27
|
-
return value unless value.parameters.empty?
|
28
|
-
value.call
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
module Persistence
|
5
|
-
# Local cache for routing topics
|
6
|
-
# We use it in order not to build string instances and remap incoming topic upon each
|
7
|
-
# message / message batches received
|
8
|
-
class Topic
|
9
|
-
# Thread.current scope under which we store topics data
|
10
|
-
PERSISTENCE_SCOPE = :topics
|
11
|
-
|
12
|
-
# @param group_id [String] group id for which we fetch a topic representation
|
13
|
-
# @param raw_topic_name [String] raw topic name (before remapping) for which we fetch a
|
14
|
-
# topic representation
|
15
|
-
# @return [Karafka::Routing::Topic] remapped topic representation that can be used further
|
16
|
-
# on when working with given parameters
|
17
|
-
def self.fetch(group_id, raw_topic_name)
|
18
|
-
Thread.current[PERSISTENCE_SCOPE] ||= Hash.new { |hash, key| hash[key] = {} }
|
19
|
-
|
20
|
-
Thread.current[PERSISTENCE_SCOPE][group_id][raw_topic_name] ||= begin
|
21
|
-
# We map from incoming topic name, as it might be namespaced, etc.
|
22
|
-
# @see topic_mapper internal docs
|
23
|
-
mapped_topic_name = Karafka::App.config.topic_mapper.incoming(raw_topic_name)
|
24
|
-
Routing::Router.find("#{group_id}_#{mapped_topic_name}")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
# Namespace for all the validation schemas that we use to check input
|
5
|
-
module Schemas
|
6
|
-
# Regexp for validating format of groups and topics
|
7
|
-
TOPIC_REGEXP = /\A(\w|\-|\.)+\z/
|
8
|
-
|
9
|
-
# Schema with validation rules for Karafka configuration details
|
10
|
-
# @note There are many more configuration options inside of the
|
11
|
-
# Karafka::Setup::Config model, but we don't validate them here as they are
|
12
|
-
# validated per each route (topic + consumer_group) because they can be overwritten,
|
13
|
-
# so we validate all of that once all the routes are defined and ready
|
14
|
-
Config = Dry::Validation.Schema do
|
15
|
-
required(:client_id).filled(:str?, format?: Karafka::Schemas::TOPIC_REGEXP)
|
16
|
-
required(:shutdown_timeout) { none? | (int? & gteq?(0)) }
|
17
|
-
required(:consumer_mapper)
|
18
|
-
required(:topic_mapper)
|
19
|
-
required(:params_base_class).filled
|
20
|
-
|
21
|
-
optional(:backend).filled
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
module Schemas
|
5
|
-
# Schema for single full route (consumer group + topics) validation.
|
6
|
-
ConsumerGroup = Dry::Validation.Schema do
|
7
|
-
# Valid uri schemas of Kafka broker url
|
8
|
-
# The ||= is due to the behavior of require_all that resolves dependencies
|
9
|
-
# but someetimes loads things twice
|
10
|
-
URI_SCHEMES ||= %w[kafka kafka+ssl plaintext ssl].freeze
|
11
|
-
|
12
|
-
# Available sasl scram mechanism of authentication (plus nil)
|
13
|
-
SASL_SCRAM_MECHANISMS ||= %w[sha256 sha512].freeze
|
14
|
-
|
15
|
-
configure do
|
16
|
-
config.messages_file = File.join(
|
17
|
-
Karafka.gem_root, 'config', 'errors.yml'
|
18
|
-
)
|
19
|
-
|
20
|
-
# Uri validator to check if uri is in a Karafka acceptable format
|
21
|
-
# @param uri [String] uri we want to validate
|
22
|
-
# @return [Boolean] true if it is a valid uri, otherwise false
|
23
|
-
def broker_schema?(uri)
|
24
|
-
uri = URI.parse(uri)
|
25
|
-
URI_SCHEMES.include?(uri.scheme) && uri.port
|
26
|
-
rescue URI::InvalidURIError
|
27
|
-
false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
required(:id).filled(:str?, format?: Karafka::Schemas::TOPIC_REGEXP)
|
32
|
-
required(:seed_brokers).filled { each(:broker_schema?) }
|
33
|
-
required(:session_timeout).filled { int? | float? }
|
34
|
-
required(:pause_timeout) { none? | ((int? | float?) & gteq?(0)) }
|
35
|
-
required(:offset_commit_interval) { int? | float? }
|
36
|
-
required(:offset_commit_threshold).filled(:int?)
|
37
|
-
required(:offset_retention_time) { none?.not > int? }
|
38
|
-
required(:heartbeat_interval).filled { (int? | float?) & gteq?(0) }
|
39
|
-
required(:fetcher_max_queue_size).filled(:int?, gt?: 0)
|
40
|
-
required(:connect_timeout).filled { (int? | float?) & gt?(0) }
|
41
|
-
required(:socket_timeout).filled { (int? | float?) & gt?(0) }
|
42
|
-
required(:min_bytes).filled(:int?, gt?: 0)
|
43
|
-
required(:max_bytes).filled(:int?, gt?: 0)
|
44
|
-
required(:max_wait_time).filled { (int? | float?) & gteq?(0) }
|
45
|
-
required(:batch_fetching).filled(:bool?)
|
46
|
-
required(:topics).filled { each { schema(ConsumerGroupTopic) } }
|
47
|
-
|
48
|
-
# Max wait time cannot exceed socket_timeout - wouldn't make sense
|
49
|
-
rule(
|
50
|
-
max_wait_time_limit: %i[max_wait_time socket_timeout]
|
51
|
-
) do |max_wait_time, socket_timeout|
|
52
|
-
socket_timeout.int? > max_wait_time.lteq?(value(:socket_timeout))
|
53
|
-
end
|
54
|
-
|
55
|
-
%i[
|
56
|
-
ssl_ca_cert
|
57
|
-
ssl_ca_cert_file_path
|
58
|
-
ssl_client_cert
|
59
|
-
ssl_client_cert_key
|
60
|
-
sasl_gssapi_principal
|
61
|
-
sasl_gssapi_keytab
|
62
|
-
sasl_plain_authzid
|
63
|
-
sasl_plain_username
|
64
|
-
sasl_plain_password
|
65
|
-
sasl_scram_username
|
66
|
-
sasl_scram_password
|
67
|
-
].each do |encryption_attribute|
|
68
|
-
optional(encryption_attribute).maybe(:str?)
|
69
|
-
end
|
70
|
-
|
71
|
-
optional(:ssl_ca_certs_from_system).maybe(:bool?)
|
72
|
-
|
73
|
-
# It's not with other encryptions as it has some more rules
|
74
|
-
optional(:sasl_scram_mechanism)
|
75
|
-
.maybe(:str?, included_in?: Karafka::Schemas::SASL_SCRAM_MECHANISMS)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
module Schemas
|
5
|
-
# Consumer group topic validation rules
|
6
|
-
ConsumerGroupTopic = Dry::Validation.Schema do
|
7
|
-
required(:id).filled(:str?, format?: Karafka::Schemas::TOPIC_REGEXP)
|
8
|
-
required(:name).filled(:str?, format?: Karafka::Schemas::TOPIC_REGEXP)
|
9
|
-
required(:backend).filled(included_in?: %i[inline sidekiq])
|
10
|
-
required(:consumer).filled
|
11
|
-
required(:parser).filled
|
12
|
-
required(:max_bytes_per_partition).filled(:int?, gteq?: 0)
|
13
|
-
required(:start_from_beginning).filled(:bool?)
|
14
|
-
required(:batch_consuming).filled(:bool?)
|
15
|
-
required(:persistent).filled(:bool?)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
module Schemas
|
5
|
-
# Validator to check responder topic usage
|
6
|
-
ResponderUsageTopic = Dry::Validation.Schema do
|
7
|
-
required(:name).filled(:str?, format?: Karafka::Schemas::TOPIC_REGEXP)
|
8
|
-
required(:required).filled(:bool?)
|
9
|
-
required(:multiple_usage).filled(:bool?)
|
10
|
-
required(:usage_count).filled(:int?, gteq?: 0)
|
11
|
-
required(:registered).filled(eql?: true)
|
12
|
-
required(:async).filled(:bool?)
|
13
|
-
|
14
|
-
rule(
|
15
|
-
required_usage: %i[required usage_count]
|
16
|
-
) do |required, usage_count|
|
17
|
-
required.true? > usage_count.gteq?(1)
|
18
|
-
end
|
19
|
-
|
20
|
-
rule(
|
21
|
-
multiple_usage_permission: %i[multiple_usage usage_count]
|
22
|
-
) do |multiple_usage, usage_count|
|
23
|
-
usage_count.gt?(1) > multiple_usage.true?
|
24
|
-
end
|
25
|
-
|
26
|
-
rule(
|
27
|
-
multiple_usage_block: %i[multiple_usage usage_count]
|
28
|
-
) do |multiple_usage, usage_count|
|
29
|
-
multiple_usage.false? > usage_count.lteq?(1)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Validator to check that everything in a responder flow matches responder rules
|
34
|
-
ResponderUsage = Dry::Validation.Schema do
|
35
|
-
required(:used_topics) { filled? > each { schema(ResponderUsageTopic) } }
|
36
|
-
required(:registered_topics) { filled? > each { schema(ResponderUsageTopic) } }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|