karafka 1.2.2 → 1.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/.coditsu/ci.yml +3 -0
  5. data/.console_irbrc +1 -3
  6. data/.diffend.yml +3 -0
  7. data/.github/FUNDING.yml +3 -0
  8. data/.github/ISSUE_TEMPLATE/bug_report.md +50 -0
  9. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  10. data/.github/workflows/ci.yml +52 -0
  11. data/.gitignore +1 -0
  12. data/.ruby-version +1 -1
  13. data/CHANGELOG.md +157 -13
  14. data/CODE_OF_CONDUCT.md +1 -1
  15. data/CONTRIBUTING.md +1 -1
  16. data/Gemfile +5 -2
  17. data/Gemfile.lock +95 -79
  18. data/README.md +15 -3
  19. data/bin/karafka +1 -1
  20. data/certs/mensfeld.pem +25 -0
  21. data/config/errors.yml +38 -5
  22. data/docker-compose.yml +17 -0
  23. data/karafka.gemspec +19 -13
  24. data/lib/karafka.rb +10 -16
  25. data/lib/karafka/app.rb +14 -6
  26. data/lib/karafka/attributes_map.rb +13 -18
  27. data/lib/karafka/base_consumer.rb +19 -30
  28. data/lib/karafka/base_responder.rb +51 -29
  29. data/lib/karafka/cli.rb +2 -2
  30. data/lib/karafka/cli/console.rb +11 -9
  31. data/lib/karafka/cli/flow.rb +9 -7
  32. data/lib/karafka/cli/info.rb +4 -2
  33. data/lib/karafka/cli/install.rb +30 -6
  34. data/lib/karafka/cli/server.rb +11 -6
  35. data/lib/karafka/code_reloader.rb +67 -0
  36. data/lib/karafka/connection/{config_adapter.rb → api_adapter.rb} +62 -21
  37. data/lib/karafka/connection/batch_delegator.rb +55 -0
  38. data/lib/karafka/connection/builder.rb +18 -0
  39. data/lib/karafka/connection/client.rb +40 -40
  40. data/lib/karafka/connection/listener.rb +26 -15
  41. data/lib/karafka/connection/message_delegator.rb +36 -0
  42. data/lib/karafka/consumers/batch_metadata.rb +10 -0
  43. data/lib/karafka/consumers/callbacks.rb +32 -15
  44. data/lib/karafka/consumers/includer.rb +31 -18
  45. data/lib/karafka/consumers/responders.rb +2 -2
  46. data/lib/karafka/contracts.rb +10 -0
  47. data/lib/karafka/contracts/config.rb +21 -0
  48. data/lib/karafka/contracts/consumer_group.rb +206 -0
  49. data/lib/karafka/contracts/consumer_group_topic.rb +19 -0
  50. data/lib/karafka/contracts/responder_usage.rb +54 -0
  51. data/lib/karafka/contracts/server_cli_options.rb +31 -0
  52. data/lib/karafka/errors.rb +17 -19
  53. data/lib/karafka/fetcher.rb +28 -30
  54. data/lib/karafka/helpers/class_matcher.rb +12 -2
  55. data/lib/karafka/helpers/config_retriever.rb +1 -1
  56. data/lib/karafka/helpers/inflector.rb +26 -0
  57. data/lib/karafka/helpers/multi_delegator.rb +0 -1
  58. data/lib/karafka/instrumentation/logger.rb +9 -6
  59. data/lib/karafka/instrumentation/monitor.rb +15 -9
  60. data/lib/karafka/instrumentation/proctitle_listener.rb +36 -0
  61. data/lib/karafka/instrumentation/stdout_listener.rb +140 -0
  62. data/lib/karafka/params/batch_metadata.rb +26 -0
  63. data/lib/karafka/params/builders/batch_metadata.rb +30 -0
  64. data/lib/karafka/params/builders/params.rb +38 -0
  65. data/lib/karafka/params/builders/params_batch.rb +25 -0
  66. data/lib/karafka/params/metadata.rb +20 -0
  67. data/lib/karafka/params/params.rb +50 -0
  68. data/lib/karafka/params/params_batch.rb +35 -21
  69. data/lib/karafka/patches/ruby_kafka.rb +21 -8
  70. data/lib/karafka/persistence/client.rb +15 -11
  71. data/lib/karafka/persistence/{consumer.rb → consumers.rb} +20 -13
  72. data/lib/karafka/persistence/topics.rb +48 -0
  73. data/lib/karafka/process.rb +0 -4
  74. data/lib/karafka/responders/builder.rb +1 -1
  75. data/lib/karafka/responders/topic.rb +6 -8
  76. data/lib/karafka/routing/builder.rb +36 -8
  77. data/lib/karafka/routing/consumer_group.rb +1 -1
  78. data/lib/karafka/routing/consumer_mapper.rb +9 -9
  79. data/lib/karafka/routing/proxy.rb +10 -1
  80. data/lib/karafka/routing/topic.rb +5 -3
  81. data/lib/karafka/routing/topic_mapper.rb +16 -18
  82. data/lib/karafka/serialization/json/deserializer.rb +27 -0
  83. data/lib/karafka/serialization/json/serializer.rb +31 -0
  84. data/lib/karafka/server.rb +34 -49
  85. data/lib/karafka/setup/config.rb +74 -40
  86. data/lib/karafka/setup/configurators/water_drop.rb +7 -3
  87. data/lib/karafka/setup/dsl.rb +0 -1
  88. data/lib/karafka/status.rb +7 -3
  89. data/lib/karafka/templates/{application_consumer.rb.example → application_consumer.rb.erb} +2 -1
  90. data/lib/karafka/templates/{application_responder.rb.example → application_responder.rb.erb} +0 -0
  91. data/lib/karafka/templates/karafka.rb.erb +92 -0
  92. data/lib/karafka/version.rb +1 -1
  93. metadata +97 -73
  94. metadata.gz.sig +4 -0
  95. data/.travis.yml +0 -13
  96. data/lib/karafka/callbacks.rb +0 -30
  97. data/lib/karafka/callbacks/config.rb +0 -22
  98. data/lib/karafka/callbacks/dsl.rb +0 -16
  99. data/lib/karafka/connection/delegator.rb +0 -46
  100. data/lib/karafka/instrumentation/listener.rb +0 -112
  101. data/lib/karafka/loader.rb +0 -28
  102. data/lib/karafka/params/dsl.rb +0 -156
  103. data/lib/karafka/parsers/json.rb +0 -38
  104. data/lib/karafka/patches/dry_configurable.rb +0 -35
  105. data/lib/karafka/persistence/topic.rb +0 -29
  106. data/lib/karafka/schemas/config.rb +0 -24
  107. data/lib/karafka/schemas/consumer_group.rb +0 -77
  108. data/lib/karafka/schemas/consumer_group_topic.rb +0 -18
  109. data/lib/karafka/schemas/responder_usage.rb +0 -39
  110. data/lib/karafka/schemas/server_cli_options.rb +0 -43
  111. data/lib/karafka/setup/configurators/base.rb +0 -29
  112. data/lib/karafka/setup/configurators/params.rb +0 -25
  113. data/lib/karafka/templates/karafka.rb.example +0 -54
data/lib/karafka.rb CHANGED
@@ -1,20 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  %w[
4
+ delegate
4
5
  English
5
6
  waterdrop
6
7
  kafka
7
8
  envlogic
9
+ json
8
10
  thor
11
+ forwardable
9
12
  fileutils
10
- multi_json
11
- require_all
12
13
  dry-configurable
13
14
  dry-validation
15
+ dry/events/publisher
14
16
  dry/inflector
15
17
  dry/monitor/notifications
16
- active_support/callbacks
17
- karafka/loader
18
+ dry/core/constants
19
+ zeitwerk
18
20
  ].each(&method(:require))
19
21
 
20
22
  # Karafka library
@@ -62,17 +64,9 @@ module Karafka
62
64
  end
63
65
  end
64
66
 
65
- %w[
66
- callbacks
67
- callbacks/*
68
- setup/dsl
69
- setup/config
70
- status
71
- schemas/config
72
- schemas/consumer_group_topic
73
- schemas/consumer_group
74
- ].each { |path| require_all File.join(Karafka.core_root, path + '.rb') }
67
+ Zeitwerk::Loader
68
+ .for_gem
69
+ .tap(&:setup)
70
+ .tap(&:eager_load)
75
71
 
76
- Karafka::Loader.load!(Karafka.core_root)
77
72
  Kafka::Consumer.prepend(Karafka::Patches::RubyKafka)
78
- Dry::Configurable::Config.prepend(Karafka::Patches::DryConfigurable)
data/lib/karafka/app.rb CHANGED
@@ -4,28 +4,36 @@ module Karafka
4
4
  # App class
5
5
  class App
6
6
  extend Setup::Dsl
7
- extend Callbacks::Dsl
8
7
 
9
8
  class << self
10
9
  # Sets up all the internal components and bootstrap whole app
11
10
  # We need to know details about consumers in order to setup components,
12
11
  # that's why we don't setup them after std setup is done
13
- # @raise [Karafka::Errors::InvalidConfiguration] raised when configuration
14
- # doesn't match with ConfigurationSchema
12
+ # @raise [Karafka::Errors::InvalidConfigurationError] raised when configuration
13
+ # doesn't match with the config contract
15
14
  def boot!
15
+ initialize!
16
16
  Setup::Config.validate!
17
17
  Setup::Config.setup_components
18
- Callbacks.after_init(Karafka::App.config)
18
+ initialized!
19
19
  end
20
20
 
21
21
  # @return [Karafka::Routing::Builder] consumers builder instance
22
22
  def consumer_groups
23
- Routing::Builder.instance
23
+ config.internal.routing_builder
24
+ end
25
+
26
+ # Triggers reload of all cached Karafka app components, so we can use in-process
27
+ # in-development hot code reloading without Karafka process restart
28
+ def reload
29
+ Karafka::Persistence::Consumers.clear
30
+ Karafka::Persistence::Topics.clear
31
+ config.internal.routing_builder.reload
24
32
  end
25
33
 
26
34
  Status.instance_methods(false).each do |delegated|
27
35
  define_method(delegated) do
28
- Status.instance.send(delegated)
36
+ App.config.internal.status.send(delegated)
29
37
  end
30
38
  end
31
39
 
@@ -11,18 +11,18 @@ module Karafka
11
11
  module AttributesMap
12
12
  class << self
13
13
  # What settings should go where in ruby-kafka
14
+ # @return [Hash] hash with proper sections on what to proxy where in Ruby-Kafka
14
15
  # @note All other settings will be passed to Kafka.new method invocation.
15
16
  # All elements in this hash are just edge cases
16
- # @return [Hash] hash with proper sections on what to proxy where in Ruby-Kafka
17
- def config_adapter
17
+ def api_adapter
18
18
  {
19
19
  consumer: %i[
20
20
  session_timeout offset_commit_interval offset_commit_threshold
21
- offset_retention_time heartbeat_interval
21
+ offset_retention_time heartbeat_interval fetcher_max_queue_size
22
22
  ],
23
- subscription: %i[start_from_beginning max_bytes_per_partition],
24
- consuming: %i[min_bytes max_bytes max_wait_time],
25
- pausing: %i[pause_timeout],
23
+ subscribe: %i[start_from_beginning max_bytes_per_partition],
24
+ consumption: %i[min_bytes max_bytes max_wait_time],
25
+ pause: %i[pause_timeout pause_max_timeout pause_exponential_backoff],
26
26
  # All the options that are under kafka config namespace, but are not used
27
27
  # directly with kafka api, but from the Karafka user perspective, they are
28
28
  # still related to kafka. They should not be proxied anywhere
@@ -32,13 +32,12 @@ module Karafka
32
32
 
33
33
  # @return [Array<Symbol>] properties that can be set on a per topic level
34
34
  def topic
35
- (config_adapter[:subscription] + %i[
35
+ (api_adapter[:subscribe] + %i[
36
36
  backend
37
37
  name
38
- parser
38
+ deserializer
39
39
  responder
40
40
  batch_consuming
41
- persistent
42
41
  ]).uniq
43
42
  end
44
43
 
@@ -48,17 +47,13 @@ module Karafka
48
47
  # Thanks to this solution, if any new setting is available for ruby-kafka, we just need
49
48
  # to add it to our configuration class and it will be handled automatically.
50
49
  def consumer_group
51
- # @note We don't ignore the config_adapter[:ignored] values as they should be ignored
50
+ # @note We don't ignore the api_adapter[:ignored] values as they should be ignored
52
51
  # only when proxying details go ruby-kafka. We use ignored fields internally in karafka
53
- ignored_settings = config_adapter[:subscription]
54
- defined_settings = config_adapter.values.flatten
52
+ ignored_settings = api_adapter[:subscribe]
53
+ defined_settings = api_adapter.values.flatten
55
54
  karafka_settings = %i[batch_fetching]
56
- # This is a drity and bad hack of dry-configurable to get keys before setting values
57
- dynamically_proxied = Karafka::Setup::Config
58
- ._settings
59
- .find { |s| s.name == :kafka }
60
- .value
61
- .instance_variable_get('@klass').settings
55
+
56
+ dynamically_proxied = Karafka::Setup::Config.config.kafka.to_h.keys
62
57
 
63
58
  (defined_settings + dynamically_proxied).uniq + karafka_settings - ignored_settings
64
59
  end
@@ -4,41 +4,33 @@
4
4
  module Karafka
5
5
  # Base consumer from which all Karafka consumers should inherit
6
6
  class BaseConsumer
7
- extend ActiveSupport::DescendantsTracker
8
7
  extend Forwardable
9
8
 
10
9
  # Allows us to mark messages as consumed for non-automatic mode without having
11
10
  # to use consumer client directly. We do this that way, because most of the people should not
12
11
  # mess with the client instance directly (just in case)
13
- def_delegator :client, :mark_as_consumed
14
-
15
- private :mark_as_consumed
16
-
17
- class << self
18
- attr_reader :topic
19
-
20
- # Assigns a topic to a consumer and builds up proper consumer functionalities
21
- # so that it can cooperate with the topic settings
22
- # @param topic [Karafka::Routing::Topic]
23
- # @return [Karafka::Routing::Topic] assigned topic
24
- def topic=(topic)
25
- @topic = topic
26
- Consumers::Includer.call(self)
27
- end
12
+ %i[
13
+ mark_as_consumed
14
+ mark_as_consumed!
15
+ trigger_heartbeat
16
+ trigger_heartbeat!
17
+ ].each do |delegated_method_name|
18
+ def_delegator :client, delegated_method_name
19
+
20
+ private delegated_method_name
28
21
  end
29
22
 
30
23
  # @return [Karafka::Routing::Topic] topic to which a given consumer is subscribed
31
- def topic
32
- self.class.topic
33
- end
34
-
35
- # Creates lazy loaded params batch object
36
- # @note Until first params usage, it won't parse data at all
37
- # @param messages [Array<Kafka::FetchedMessage>, Array<Hash>] messages with raw
38
- # content (from Kafka) or messages inside a hash (from backend, etc)
39
- # @return [Karafka::Params::ParamsBatch] lazy loaded params batch
40
- def params_batch=(messages)
41
- @params_batch = Karafka::Params::ParamsBatch.new(messages, topic.parser)
24
+ attr_reader :topic
25
+ # @return [Karafka::Params:ParamsBatch] current params batch
26
+ attr_accessor :params_batch
27
+
28
+ # Assigns a topic to a consumer and builds up proper consumer functionalities
29
+ # so that it can cooperate with the topic settings
30
+ # @param topic [Karafka::Routing::Topic]
31
+ def initialize(topic)
32
+ @topic = topic
33
+ Consumers::Includer.call(self)
42
34
  end
43
35
 
44
36
  # Executes the default consumer flow.
@@ -48,9 +40,6 @@ module Karafka
48
40
 
49
41
  private
50
42
 
51
- # We make it private as it should be accessible only from the inside of a consumer
52
- attr_reader :params_batch
53
-
54
43
  # @return [Karafka::Connection::Client] messages consuming client that can be used to
55
44
  # commit manually offset or pause / stop consumer based on the business logic
56
45
  def client
@@ -39,7 +39,7 @@ module Karafka
39
39
  #
40
40
  # @example Multiple times used topic
41
41
  # class Responder < BaseResponder
42
- # topic :required_topic, multiple_usage: true
42
+ # topic :required_topic
43
43
  #
44
44
  # def respond(data)
45
45
  # data.each do |subset|
@@ -48,6 +48,17 @@ module Karafka
48
48
  # end
49
49
  # end
50
50
  #
51
+ # @example Specify serializer for a topic
52
+ # class Responder < BaseResponder
53
+ # topic :xml_topic, serializer: MyXMLSerializer
54
+ #
55
+ # def respond(data)
56
+ # data.each do |subset|
57
+ # respond_to :xml_topic, subset
58
+ # end
59
+ # end
60
+ # end
61
+ #
51
62
  # @example Accept multiple arguments to a respond method
52
63
  # class Responder < BaseResponder
53
64
  # topic :users_actions
@@ -59,31 +70,35 @@ module Karafka
59
70
  # end
60
71
  # end
61
72
  class BaseResponder
62
- # Definitions of all topics that we want to be able to use in this responder should go here
63
- class_attribute :topics
64
-
65
- # Schema that we can use to control and/or require some additional details upon options
66
- # that are being passed to the producer. This can be in particular useful if we want to make
67
- # sure that for example partition_key is always present.
68
- class_attribute :options_schema
73
+ # Responder usage contract
74
+ CONTRACT = Karafka::Contracts::ResponderUsage.new.freeze
69
75
 
70
- attr_reader :messages_buffer
76
+ private_constant :CONTRACT
71
77
 
72
78
  class << self
79
+ # Definitions of all topics that we want to be able to use in this responder should go here
80
+ attr_accessor :topics
81
+ # Contract that we can use to control and/or require some additional details upon options
82
+ # that are being passed to the producer. This can be in particular useful if we want to make
83
+ # sure that for example partition_key is always present.
84
+ attr_accessor :options_contract
85
+
73
86
  # Registers a topic as on to which we will be able to respond
74
87
  # @param topic_name [Symbol, String] name of topic to which we want to respond
75
88
  # @param options [Hash] hash with optional configuration details
76
89
  def topic(topic_name, options = {})
90
+ options[:serializer] ||= Karafka::App.config.serializer
91
+ options[:registered] = true
77
92
  self.topics ||= {}
78
- topic_obj = Responders::Topic.new(topic_name, options.merge(registered: true))
93
+ topic_obj = Responders::Topic.new(topic_name, options)
79
94
  self.topics[topic_obj.name] = topic_obj
80
95
  end
81
96
 
82
97
  # A simple alias for easier standalone responder usage.
83
- # Instead of building it with new.call it allows (in case of usin JSON parser)
98
+ # Instead of building it with new.call it allows (in case of using JSON serializer)
84
99
  # to just run it directly from the class level
85
100
  # @param data Anything that we want to respond with
86
- # @example Send user data with a responder (uses default Karafka::Parsers::Json parser)
101
+ # @example Send user data with a responder
87
102
  # UsersCreatedResponder.call(@created_user)
88
103
  def call(*data)
89
104
  # Just in case there were no topics defined for a responder, we initialize with
@@ -93,12 +108,11 @@ module Karafka
93
108
  end
94
109
  end
95
110
 
111
+ attr_reader :messages_buffer
112
+
96
113
  # Creates a responder object
97
- # @param parser_class [Class] parser class that we can use to generate appropriate string
98
- # or nothing if we want to default to Karafka::Parsers::Json
99
114
  # @return [Karafka::BaseResponder] base responder descendant responder
100
- def initialize(parser_class = Karafka::App.config.parser)
101
- @parser_class = parser_class
115
+ def initialize
102
116
  @messages_buffer = {}
103
117
  end
104
118
 
@@ -107,7 +121,7 @@ module Karafka
107
121
  # @note We know that validators should be executed also before sending data to topics, however
108
122
  # the implementation gets way more complicated then, that's why we check after everything
109
123
  # was sent using responder
110
- # @example Send user data with a responder (uses default Karafka::Parsers::Json parser)
124
+ # @example Send user data with a responder
111
125
  # UsersCreatedResponder.new.call(@created_user)
112
126
  # @example Send user data with a responder using non default Parser
113
127
  # UsersCreatedResponder.new(MyParser).call(@created_user)
@@ -134,25 +148,26 @@ module Karafka
134
148
  topic.to_h.merge!(usage_count: usage.count)
135
149
  end
136
150
 
137
- result = Karafka::Schemas::ResponderUsage.call(
151
+ result = CONTRACT.call(
138
152
  registered_topics: registered_topics,
139
153
  used_topics: used_topics
140
154
  )
141
155
 
142
156
  return if result.success?
143
157
 
144
- raise Karafka::Errors::InvalidResponderUsage, result.errors
158
+ raise Karafka::Errors::InvalidResponderUsageError, result.errors.to_h
145
159
  end
146
160
 
147
161
  # Checks if we met all the options requirements before sending them to the producer.
148
162
  def validate_options!
149
- return true unless self.class.options_schema
163
+ return true unless self.class.options_contract
150
164
 
151
165
  messages_buffer.each_value do |messages_set|
152
166
  messages_set.each do |message_data|
153
- result = self.class.options_schema.call(message_data.last)
167
+ result = self.class.options_contract.call(message_data.last)
154
168
  next if result.success?
155
- raise Karafka::Errors::InvalidResponderMessageOptions, result.errors
169
+
170
+ raise Karafka::Errors::InvalidResponderMessageOptionsError, result.errors.to_h
156
171
  end
157
172
  end
158
173
  end
@@ -163,13 +178,18 @@ module Karafka
163
178
  def deliver!
164
179
  messages_buffer.each_value do |data_elements|
165
180
  data_elements.each do |data, options|
166
- producer(options).call(data, options)
181
+ # We map this topic name, so it will match namespaced/etc topic in Kafka
182
+ # @note By default will not change topic (if default mapper used)
183
+ mapped_topic = Karafka::App.config.topic_mapper.outgoing(options[:topic])
184
+ external_options = options.merge(topic: mapped_topic)
185
+ producer(options).call(data, external_options)
167
186
  end
168
187
  end
169
188
  end
170
189
 
171
190
  # Method that needs to be implemented in a subclass. It should handle responding
172
191
  # on registered topics
192
+ # @param _data [Object] anything that we want to use to send to Kafka
173
193
  # @raise [NotImplementedError] This method needs to be implemented in a subclass
174
194
  def respond(*_data)
175
195
  raise NotImplementedError, 'Implement this in a subclass'
@@ -179,7 +199,7 @@ module Karafka
179
199
  # as many times as we need. Especially when we have 1:n flow
180
200
  # @param topic [Symbol, String] topic to which we want to respond
181
201
  # @param data [String, Object] string or object that we want to send
182
- # @param options [Hash] options for waterdrop (e.g. partition_key)
202
+ # @param options [Hash] options for waterdrop (e.g. partition_key).
183
203
  # @note Respond to does not accept multiple data arguments.
184
204
  def respond_to(topic, data, options = {})
185
205
  # We normalize the format to string, as WaterDrop and Ruby-Kafka support only
@@ -188,17 +208,19 @@ module Karafka
188
208
 
189
209
  messages_buffer[topic] ||= []
190
210
  messages_buffer[topic] << [
191
- @parser_class.generate(data),
192
- # We map this topic name, so it will match namespaced/etc topic in Kafka
193
- # @note By default will not change topic (if default mapper used)
194
- options.merge(topic: Karafka::App.config.topic_mapper.outgoing(topic))
211
+ self.class.topics[topic].serializer.call(data),
212
+ options.merge(topic: topic)
195
213
  ]
196
214
  end
197
215
 
198
216
  # @param options [Hash] options for waterdrop
199
217
  # @return [Class] WaterDrop producer (sync or async based on the settings)
200
218
  def producer(options)
201
- options[:async] ? WaterDrop::AsyncProducer : WaterDrop::SyncProducer
219
+ if self.class.topics[options[:topic]].async?
220
+ WaterDrop::AsyncProducer
221
+ else
222
+ WaterDrop::SyncProducer
223
+ end
202
224
  end
203
225
  end
204
226
  end
data/lib/karafka/cli.rb CHANGED
@@ -37,7 +37,7 @@ end
37
37
  # This is kinda trick - since we don't have a autoload and other magic stuff
38
38
  # like Rails does, so instead this method allows us to replace currently running
39
39
  # console with a new one via Kernel.exec. It will start console with new code loaded
40
- # Yes we know that it is not turbofast, however it is turbo convinient and small
40
+ # Yes, we know that it is not turbo fast, however it is turbo convenient and small
41
41
  #
42
42
  # Also - the KARAFKA_CONSOLE is used to detect that we're executing the irb session
43
43
  # so this method is only available when the Karafka console is running
@@ -47,7 +47,7 @@ end
47
47
  if ENV['KARAFKA_CONSOLE']
48
48
  # Reloads Karafka irb console session
49
49
  def reload!
50
- puts "Reloading...\n"
50
+ Karafka.logger.info "Reloading...\n"
51
51
  Kernel.exec Karafka::Cli::Console.command
52
52
  end
53
53
  end
@@ -8,15 +8,17 @@ module Karafka
8
8
  desc 'Start the Karafka console (short-cut alias: "c")'
9
9
  option aliases: 'c'
10
10
 
11
- # @return [String] Console executing command
12
- # @example
13
- # Karafka::Cli::Console.command #=> 'KARAFKA_CONSOLE=true bundle exec irb...'
14
- def self.command
15
- envs = [
16
- "IRBRC='#{Karafka.gem_root}/.console_irbrc'",
17
- 'KARAFKA_CONSOLE=true'
18
- ]
19
- "#{envs.join(' ')} bundle exec irb"
11
+ class << self
12
+ # @return [String] Console executing command
13
+ # @example
14
+ # Karafka::Cli::Console.command #=> 'KARAFKA_CONSOLE=true bundle exec irb...'
15
+ def command
16
+ envs = [
17
+ "IRBRC='#{Karafka.gem_root}/.console_irbrc'",
18
+ 'KARAFKA_CONSOLE=true'
19
+ ]
20
+ "#{envs.join(' ')} bundle exec irb -r #{Karafka.boot_file}"
21
+ end
20
22
  end
21
23
 
22
24
  # Start the Karafka console