karafka 1.4.12 → 2.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (359) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/FUNDING.yml +1 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +10 -9
  5. data/.github/workflows/ci.yml +169 -31
  6. data/.rspec +4 -0
  7. data/.ruby-version +1 -1
  8. data/CHANGELOG.md +716 -607
  9. data/CONTRIBUTING.md +10 -19
  10. data/Gemfile +7 -0
  11. data/Gemfile.lock +69 -92
  12. data/LICENSE +17 -0
  13. data/LICENSE-COMM +89 -0
  14. data/LICENSE-LGPL +165 -0
  15. data/README.md +48 -47
  16. data/bin/benchmarks +99 -0
  17. data/bin/create_token +22 -0
  18. data/bin/integrations +310 -0
  19. data/bin/karafka +5 -14
  20. data/bin/record_rss +50 -0
  21. data/bin/rspecs +6 -0
  22. data/bin/scenario +29 -0
  23. data/bin/stress_many +13 -0
  24. data/bin/stress_one +13 -0
  25. data/bin/verify_license_integrity +37 -0
  26. data/bin/wait_for_kafka +24 -0
  27. data/certs/cert_chain.pem +26 -0
  28. data/certs/karafka-pro.pem +11 -0
  29. data/config/locales/errors.yml +97 -0
  30. data/config/locales/pro_errors.yml +59 -0
  31. data/docker-compose.yml +19 -11
  32. data/karafka.gemspec +26 -22
  33. data/lib/active_job/karafka.rb +17 -0
  34. data/lib/active_job/queue_adapters/karafka_adapter.rb +32 -0
  35. data/lib/karafka/active_job/consumer.rb +49 -0
  36. data/lib/karafka/active_job/current_attributes/loading.rb +36 -0
  37. data/lib/karafka/active_job/current_attributes/persistence.rb +28 -0
  38. data/lib/karafka/active_job/current_attributes.rb +42 -0
  39. data/lib/karafka/active_job/dispatcher.rb +69 -0
  40. data/lib/karafka/active_job/job_extensions.rb +34 -0
  41. data/lib/karafka/active_job/job_options_contract.rb +32 -0
  42. data/lib/karafka/admin.rb +313 -0
  43. data/lib/karafka/app.rb +47 -23
  44. data/lib/karafka/base_consumer.rb +260 -29
  45. data/lib/karafka/cli/base.rb +67 -36
  46. data/lib/karafka/cli/console.rb +18 -12
  47. data/lib/karafka/cli/help.rb +24 -0
  48. data/lib/karafka/cli/info.rb +47 -12
  49. data/lib/karafka/cli/install.rb +23 -14
  50. data/lib/karafka/cli/server.rb +101 -44
  51. data/lib/karafka/cli/topics.rb +146 -0
  52. data/lib/karafka/cli.rb +24 -27
  53. data/lib/karafka/connection/client.rb +553 -90
  54. data/lib/karafka/connection/consumer_group_coordinator.rb +48 -0
  55. data/lib/karafka/connection/listener.rb +294 -38
  56. data/lib/karafka/connection/listeners_batch.rb +40 -0
  57. data/lib/karafka/connection/messages_buffer.rb +84 -0
  58. data/lib/karafka/connection/pauses_manager.rb +46 -0
  59. data/lib/karafka/connection/proxy.rb +98 -0
  60. data/lib/karafka/connection/raw_messages_buffer.rb +101 -0
  61. data/lib/karafka/connection/rebalance_manager.rb +105 -0
  62. data/lib/karafka/contracts/base.rb +17 -0
  63. data/lib/karafka/contracts/config.rb +130 -11
  64. data/lib/karafka/contracts/consumer_group.rb +32 -187
  65. data/lib/karafka/contracts/server_cli_options.rb +80 -19
  66. data/lib/karafka/contracts/topic.rb +65 -0
  67. data/lib/karafka/contracts.rb +1 -1
  68. data/lib/karafka/embedded.rb +36 -0
  69. data/lib/karafka/env.rb +46 -0
  70. data/lib/karafka/errors.rb +37 -21
  71. data/lib/karafka/helpers/async.rb +33 -0
  72. data/lib/karafka/helpers/colorize.rb +26 -0
  73. data/lib/karafka/helpers/multi_delegator.rb +2 -2
  74. data/lib/karafka/instrumentation/callbacks/error.rb +39 -0
  75. data/lib/karafka/instrumentation/callbacks/rebalance.rb +64 -0
  76. data/lib/karafka/instrumentation/callbacks/statistics.rb +51 -0
  77. data/lib/karafka/instrumentation/logger_listener.rb +303 -0
  78. data/lib/karafka/instrumentation/monitor.rb +13 -61
  79. data/lib/karafka/instrumentation/notifications.rb +79 -0
  80. data/lib/karafka/instrumentation/proctitle_listener.rb +7 -16
  81. data/lib/karafka/instrumentation/vendors/appsignal/base.rb +30 -0
  82. data/lib/karafka/instrumentation/vendors/appsignal/client.rb +122 -0
  83. data/lib/karafka/instrumentation/vendors/appsignal/dashboard.json +222 -0
  84. data/lib/karafka/instrumentation/vendors/appsignal/errors_listener.rb +30 -0
  85. data/lib/karafka/instrumentation/vendors/appsignal/metrics_listener.rb +331 -0
  86. data/lib/karafka/instrumentation/vendors/datadog/dashboard.json +1 -0
  87. data/lib/karafka/instrumentation/vendors/datadog/logger_listener.rb +155 -0
  88. data/lib/karafka/instrumentation/vendors/datadog/metrics_listener.rb +264 -0
  89. data/lib/karafka/instrumentation/vendors/kubernetes/liveness_listener.rb +176 -0
  90. data/lib/karafka/licenser.rb +78 -0
  91. data/lib/karafka/messages/batch_metadata.rb +52 -0
  92. data/lib/karafka/messages/builders/batch_metadata.rb +60 -0
  93. data/lib/karafka/messages/builders/message.rb +40 -0
  94. data/lib/karafka/messages/builders/messages.rb +36 -0
  95. data/lib/karafka/{params/params.rb → messages/message.rb} +20 -13
  96. data/lib/karafka/messages/messages.rb +71 -0
  97. data/lib/karafka/{params → messages}/metadata.rb +4 -6
  98. data/lib/karafka/messages/parser.rb +14 -0
  99. data/lib/karafka/messages/seek.rb +12 -0
  100. data/lib/karafka/patches/rdkafka/bindings.rb +122 -0
  101. data/lib/karafka/patches/rdkafka/opaque.rb +36 -0
  102. data/lib/karafka/pro/active_job/consumer.rb +47 -0
  103. data/lib/karafka/pro/active_job/dispatcher.rb +86 -0
  104. data/lib/karafka/pro/active_job/job_options_contract.rb +45 -0
  105. data/lib/karafka/pro/cleaner/errors.rb +27 -0
  106. data/lib/karafka/pro/cleaner/messages/message.rb +46 -0
  107. data/lib/karafka/pro/cleaner/messages/messages.rb +42 -0
  108. data/lib/karafka/pro/cleaner.rb +41 -0
  109. data/lib/karafka/pro/contracts/base.rb +23 -0
  110. data/lib/karafka/pro/contracts/server_cli_options.rb +111 -0
  111. data/lib/karafka/pro/encryption/cipher.rb +58 -0
  112. data/lib/karafka/pro/encryption/contracts/config.rb +79 -0
  113. data/lib/karafka/pro/encryption/errors.rb +27 -0
  114. data/lib/karafka/pro/encryption/messages/middleware.rb +46 -0
  115. data/lib/karafka/pro/encryption/messages/parser.rb +56 -0
  116. data/lib/karafka/pro/encryption/setup/config.rb +48 -0
  117. data/lib/karafka/pro/encryption.rb +47 -0
  118. data/lib/karafka/pro/iterator/expander.rb +95 -0
  119. data/lib/karafka/pro/iterator/tpl_builder.rb +155 -0
  120. data/lib/karafka/pro/iterator.rb +170 -0
  121. data/lib/karafka/pro/loader.rb +106 -0
  122. data/lib/karafka/pro/performance_tracker.rb +84 -0
  123. data/lib/karafka/pro/processing/collapser.rb +62 -0
  124. data/lib/karafka/pro/processing/coordinator.rb +147 -0
  125. data/lib/karafka/pro/processing/filters/base.rb +61 -0
  126. data/lib/karafka/pro/processing/filters/delayer.rb +70 -0
  127. data/lib/karafka/pro/processing/filters/expirer.rb +51 -0
  128. data/lib/karafka/pro/processing/filters/inline_insights_delayer.rb +78 -0
  129. data/lib/karafka/pro/processing/filters/throttler.rb +84 -0
  130. data/lib/karafka/pro/processing/filters/virtual_limiter.rb +52 -0
  131. data/lib/karafka/pro/processing/filters_applier.rb +105 -0
  132. data/lib/karafka/pro/processing/jobs/consume_non_blocking.rb +39 -0
  133. data/lib/karafka/pro/processing/jobs/revoked_non_blocking.rb +37 -0
  134. data/lib/karafka/pro/processing/jobs_builder.rb +50 -0
  135. data/lib/karafka/pro/processing/partitioner.rb +69 -0
  136. data/lib/karafka/pro/processing/scheduler.rb +75 -0
  137. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom.rb +70 -0
  138. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom_vp.rb +76 -0
  139. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom.rb +72 -0
  140. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom_vp.rb +76 -0
  141. data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom.rb +66 -0
  142. data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom_vp.rb +70 -0
  143. data/lib/karafka/pro/processing/strategies/aj/dlq_mom.rb +64 -0
  144. data/lib/karafka/pro/processing/strategies/aj/dlq_mom_vp.rb +69 -0
  145. data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom.rb +38 -0
  146. data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom_vp.rb +66 -0
  147. data/lib/karafka/pro/processing/strategies/aj/ftr_mom.rb +38 -0
  148. data/lib/karafka/pro/processing/strategies/aj/ftr_mom_vp.rb +58 -0
  149. data/lib/karafka/pro/processing/strategies/aj/lrj_mom.rb +37 -0
  150. data/lib/karafka/pro/processing/strategies/aj/lrj_mom_vp.rb +82 -0
  151. data/lib/karafka/pro/processing/strategies/aj/mom.rb +36 -0
  152. data/lib/karafka/pro/processing/strategies/aj/mom_vp.rb +52 -0
  153. data/lib/karafka/pro/processing/strategies/base.rb +26 -0
  154. data/lib/karafka/pro/processing/strategies/default.rb +105 -0
  155. data/lib/karafka/pro/processing/strategies/dlq/default.rb +137 -0
  156. data/lib/karafka/pro/processing/strategies/dlq/ftr.rb +61 -0
  157. data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj.rb +75 -0
  158. data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom.rb +71 -0
  159. data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom_vp.rb +43 -0
  160. data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_vp.rb +41 -0
  161. data/lib/karafka/pro/processing/strategies/dlq/ftr_mom.rb +69 -0
  162. data/lib/karafka/pro/processing/strategies/dlq/ftr_mom_vp.rb +41 -0
  163. data/lib/karafka/pro/processing/strategies/dlq/ftr_vp.rb +40 -0
  164. data/lib/karafka/pro/processing/strategies/dlq/lrj.rb +64 -0
  165. data/lib/karafka/pro/processing/strategies/dlq/lrj_mom.rb +65 -0
  166. data/lib/karafka/pro/processing/strategies/dlq/lrj_mom_vp.rb +36 -0
  167. data/lib/karafka/pro/processing/strategies/dlq/lrj_vp.rb +39 -0
  168. data/lib/karafka/pro/processing/strategies/dlq/mom.rb +68 -0
  169. data/lib/karafka/pro/processing/strategies/dlq/mom_vp.rb +37 -0
  170. data/lib/karafka/pro/processing/strategies/dlq/vp.rb +40 -0
  171. data/lib/karafka/pro/processing/strategies/ftr/default.rb +111 -0
  172. data/lib/karafka/pro/processing/strategies/ftr/vp.rb +40 -0
  173. data/lib/karafka/pro/processing/strategies/lrj/default.rb +85 -0
  174. data/lib/karafka/pro/processing/strategies/lrj/ftr.rb +69 -0
  175. data/lib/karafka/pro/processing/strategies/lrj/ftr_mom.rb +67 -0
  176. data/lib/karafka/pro/processing/strategies/lrj/ftr_mom_vp.rb +40 -0
  177. data/lib/karafka/pro/processing/strategies/lrj/ftr_vp.rb +39 -0
  178. data/lib/karafka/pro/processing/strategies/lrj/mom.rb +77 -0
  179. data/lib/karafka/pro/processing/strategies/lrj/mom_vp.rb +38 -0
  180. data/lib/karafka/pro/processing/strategies/lrj/vp.rb +36 -0
  181. data/lib/karafka/pro/processing/strategies/mom/default.rb +46 -0
  182. data/lib/karafka/pro/processing/strategies/mom/ftr.rb +53 -0
  183. data/lib/karafka/pro/processing/strategies/mom/ftr_vp.rb +37 -0
  184. data/lib/karafka/pro/processing/strategies/mom/vp.rb +35 -0
  185. data/lib/karafka/pro/processing/strategies/vp/default.rb +124 -0
  186. data/lib/karafka/pro/processing/strategies.rb +22 -0
  187. data/lib/karafka/pro/processing/strategy_selector.rb +84 -0
  188. data/lib/karafka/pro/processing/virtual_offset_manager.rb +147 -0
  189. data/lib/karafka/pro/routing/features/active_job/builder.rb +45 -0
  190. data/lib/karafka/pro/routing/features/active_job.rb +26 -0
  191. data/lib/karafka/pro/routing/features/base.rb +24 -0
  192. data/lib/karafka/pro/routing/features/dead_letter_queue/contracts/topic.rb +53 -0
  193. data/lib/karafka/pro/routing/features/dead_letter_queue.rb +27 -0
  194. data/lib/karafka/pro/routing/features/delaying/config.rb +27 -0
  195. data/lib/karafka/pro/routing/features/delaying/contracts/topic.rb +41 -0
  196. data/lib/karafka/pro/routing/features/delaying/topic.rb +59 -0
  197. data/lib/karafka/pro/routing/features/delaying.rb +29 -0
  198. data/lib/karafka/pro/routing/features/expiring/config.rb +27 -0
  199. data/lib/karafka/pro/routing/features/expiring/contracts/topic.rb +41 -0
  200. data/lib/karafka/pro/routing/features/expiring/topic.rb +59 -0
  201. data/lib/karafka/pro/routing/features/expiring.rb +27 -0
  202. data/lib/karafka/pro/routing/features/filtering/config.rb +40 -0
  203. data/lib/karafka/pro/routing/features/filtering/contracts/topic.rb +44 -0
  204. data/lib/karafka/pro/routing/features/filtering/topic.rb +51 -0
  205. data/lib/karafka/pro/routing/features/filtering.rb +27 -0
  206. data/lib/karafka/pro/routing/features/inline_insights/config.rb +32 -0
  207. data/lib/karafka/pro/routing/features/inline_insights/contracts/topic.rb +41 -0
  208. data/lib/karafka/pro/routing/features/inline_insights/topic.rb +52 -0
  209. data/lib/karafka/pro/routing/features/inline_insights.rb +26 -0
  210. data/lib/karafka/pro/routing/features/long_running_job/config.rb +28 -0
  211. data/lib/karafka/pro/routing/features/long_running_job/contracts/topic.rb +40 -0
  212. data/lib/karafka/pro/routing/features/long_running_job/topic.rb +42 -0
  213. data/lib/karafka/pro/routing/features/long_running_job.rb +28 -0
  214. data/lib/karafka/pro/routing/features/patterns/builder.rb +38 -0
  215. data/lib/karafka/pro/routing/features/patterns/config.rb +54 -0
  216. data/lib/karafka/pro/routing/features/patterns/consumer_group.rb +72 -0
  217. data/lib/karafka/pro/routing/features/patterns/contracts/consumer_group.rb +62 -0
  218. data/lib/karafka/pro/routing/features/patterns/contracts/pattern.rb +46 -0
  219. data/lib/karafka/pro/routing/features/patterns/contracts/topic.rb +41 -0
  220. data/lib/karafka/pro/routing/features/patterns/detector.rb +71 -0
  221. data/lib/karafka/pro/routing/features/patterns/pattern.rb +95 -0
  222. data/lib/karafka/pro/routing/features/patterns/patterns.rb +35 -0
  223. data/lib/karafka/pro/routing/features/patterns/topic.rb +50 -0
  224. data/lib/karafka/pro/routing/features/patterns/topics.rb +53 -0
  225. data/lib/karafka/pro/routing/features/patterns.rb +33 -0
  226. data/lib/karafka/pro/routing/features/pausing/contracts/topic.rb +51 -0
  227. data/lib/karafka/pro/routing/features/pausing/topic.rb +44 -0
  228. data/lib/karafka/pro/routing/features/pausing.rb +25 -0
  229. data/lib/karafka/pro/routing/features/throttling/config.rb +32 -0
  230. data/lib/karafka/pro/routing/features/throttling/contracts/topic.rb +44 -0
  231. data/lib/karafka/pro/routing/features/throttling/topic.rb +69 -0
  232. data/lib/karafka/pro/routing/features/throttling.rb +30 -0
  233. data/lib/karafka/pro/routing/features/virtual_partitions/config.rb +30 -0
  234. data/lib/karafka/pro/routing/features/virtual_partitions/contracts/topic.rb +55 -0
  235. data/lib/karafka/pro/routing/features/virtual_partitions/topic.rb +56 -0
  236. data/lib/karafka/pro/routing/features/virtual_partitions.rb +27 -0
  237. data/lib/karafka/pro.rb +13 -0
  238. data/lib/karafka/process.rb +24 -8
  239. data/lib/karafka/processing/coordinator.rb +181 -0
  240. data/lib/karafka/processing/coordinators_buffer.rb +62 -0
  241. data/lib/karafka/processing/executor.rb +155 -0
  242. data/lib/karafka/processing/executors_buffer.rb +72 -0
  243. data/lib/karafka/processing/expansions_selector.rb +22 -0
  244. data/lib/karafka/processing/inline_insights/consumer.rb +41 -0
  245. data/lib/karafka/processing/inline_insights/listener.rb +19 -0
  246. data/lib/karafka/processing/inline_insights/tracker.rb +128 -0
  247. data/lib/karafka/processing/jobs/base.rb +55 -0
  248. data/lib/karafka/processing/jobs/consume.rb +45 -0
  249. data/lib/karafka/processing/jobs/idle.rb +24 -0
  250. data/lib/karafka/processing/jobs/revoked.rb +22 -0
  251. data/lib/karafka/processing/jobs/shutdown.rb +23 -0
  252. data/lib/karafka/processing/jobs_builder.rb +28 -0
  253. data/lib/karafka/processing/jobs_queue.rb +150 -0
  254. data/lib/karafka/processing/partitioner.rb +24 -0
  255. data/lib/karafka/processing/result.rb +42 -0
  256. data/lib/karafka/processing/scheduler.rb +22 -0
  257. data/lib/karafka/processing/strategies/aj_dlq_mom.rb +44 -0
  258. data/lib/karafka/processing/strategies/aj_mom.rb +21 -0
  259. data/lib/karafka/processing/strategies/base.rb +52 -0
  260. data/lib/karafka/processing/strategies/default.rb +158 -0
  261. data/lib/karafka/processing/strategies/dlq.rb +88 -0
  262. data/lib/karafka/processing/strategies/dlq_mom.rb +49 -0
  263. data/lib/karafka/processing/strategies/mom.rb +29 -0
  264. data/lib/karafka/processing/strategy_selector.rb +47 -0
  265. data/lib/karafka/processing/worker.rb +93 -0
  266. data/lib/karafka/processing/workers_batch.rb +27 -0
  267. data/lib/karafka/railtie.rb +141 -0
  268. data/lib/karafka/routing/activity_manager.rb +84 -0
  269. data/lib/karafka/routing/builder.rb +45 -19
  270. data/lib/karafka/routing/consumer_group.rb +56 -20
  271. data/lib/karafka/routing/consumer_mapper.rb +1 -12
  272. data/lib/karafka/routing/features/active_job/builder.rb +33 -0
  273. data/lib/karafka/routing/features/active_job/config.rb +15 -0
  274. data/lib/karafka/routing/features/active_job/contracts/topic.rb +44 -0
  275. data/lib/karafka/routing/features/active_job/proxy.rb +14 -0
  276. data/lib/karafka/routing/features/active_job/topic.rb +33 -0
  277. data/lib/karafka/routing/features/active_job.rb +13 -0
  278. data/lib/karafka/routing/features/base/expander.rb +59 -0
  279. data/lib/karafka/routing/features/base.rb +71 -0
  280. data/lib/karafka/routing/features/dead_letter_queue/config.rb +19 -0
  281. data/lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb +46 -0
  282. data/lib/karafka/routing/features/dead_letter_queue/topic.rb +41 -0
  283. data/lib/karafka/routing/features/dead_letter_queue.rb +16 -0
  284. data/lib/karafka/routing/features/declaratives/config.rb +18 -0
  285. data/lib/karafka/routing/features/declaratives/contracts/topic.rb +33 -0
  286. data/lib/karafka/routing/features/declaratives/topic.rb +44 -0
  287. data/lib/karafka/routing/features/declaratives.rb +14 -0
  288. data/lib/karafka/routing/features/inline_insights/config.rb +15 -0
  289. data/lib/karafka/routing/features/inline_insights/contracts/topic.rb +27 -0
  290. data/lib/karafka/routing/features/inline_insights/topic.rb +31 -0
  291. data/lib/karafka/routing/features/inline_insights.rb +40 -0
  292. data/lib/karafka/routing/features/manual_offset_management/config.rb +15 -0
  293. data/lib/karafka/routing/features/manual_offset_management/contracts/topic.rb +27 -0
  294. data/lib/karafka/routing/features/manual_offset_management/topic.rb +35 -0
  295. data/lib/karafka/routing/features/manual_offset_management.rb +18 -0
  296. data/lib/karafka/routing/proxy.rb +22 -21
  297. data/lib/karafka/routing/router.rb +24 -10
  298. data/lib/karafka/routing/subscription_group.rb +110 -0
  299. data/lib/karafka/routing/subscription_groups_builder.rb +65 -0
  300. data/lib/karafka/routing/topic.rb +87 -24
  301. data/lib/karafka/routing/topics.rb +46 -0
  302. data/lib/karafka/runner.rb +52 -0
  303. data/lib/karafka/serialization/json/deserializer.rb +7 -15
  304. data/lib/karafka/server.rb +113 -37
  305. data/lib/karafka/setup/attributes_map.rb +348 -0
  306. data/lib/karafka/setup/config.rb +256 -175
  307. data/lib/karafka/status.rb +54 -7
  308. data/lib/karafka/templates/example_consumer.rb.erb +16 -0
  309. data/lib/karafka/templates/karafka.rb.erb +33 -55
  310. data/lib/karafka/time_trackers/base.rb +14 -0
  311. data/lib/karafka/time_trackers/pause.rb +122 -0
  312. data/lib/karafka/time_trackers/poll.rb +69 -0
  313. data/lib/karafka/version.rb +1 -1
  314. data/lib/karafka.rb +91 -17
  315. data/renovate.json +9 -0
  316. data.tar.gz.sig +0 -0
  317. metadata +330 -168
  318. metadata.gz.sig +0 -0
  319. data/MIT-LICENCE +0 -18
  320. data/certs/mensfeld.pem +0 -25
  321. data/config/errors.yml +0 -41
  322. data/lib/karafka/assignment_strategies/round_robin.rb +0 -13
  323. data/lib/karafka/attributes_map.rb +0 -63
  324. data/lib/karafka/backends/inline.rb +0 -16
  325. data/lib/karafka/base_responder.rb +0 -226
  326. data/lib/karafka/cli/flow.rb +0 -48
  327. data/lib/karafka/cli/missingno.rb +0 -19
  328. data/lib/karafka/code_reloader.rb +0 -67
  329. data/lib/karafka/connection/api_adapter.rb +0 -158
  330. data/lib/karafka/connection/batch_delegator.rb +0 -55
  331. data/lib/karafka/connection/builder.rb +0 -23
  332. data/lib/karafka/connection/message_delegator.rb +0 -36
  333. data/lib/karafka/consumers/batch_metadata.rb +0 -10
  334. data/lib/karafka/consumers/callbacks.rb +0 -71
  335. data/lib/karafka/consumers/includer.rb +0 -64
  336. data/lib/karafka/consumers/responders.rb +0 -24
  337. data/lib/karafka/consumers/single_params.rb +0 -15
  338. data/lib/karafka/contracts/consumer_group_topic.rb +0 -19
  339. data/lib/karafka/contracts/responder_usage.rb +0 -54
  340. data/lib/karafka/fetcher.rb +0 -42
  341. data/lib/karafka/helpers/class_matcher.rb +0 -88
  342. data/lib/karafka/helpers/config_retriever.rb +0 -46
  343. data/lib/karafka/helpers/inflector.rb +0 -26
  344. data/lib/karafka/instrumentation/stdout_listener.rb +0 -140
  345. data/lib/karafka/params/batch_metadata.rb +0 -26
  346. data/lib/karafka/params/builders/batch_metadata.rb +0 -30
  347. data/lib/karafka/params/builders/params.rb +0 -38
  348. data/lib/karafka/params/builders/params_batch.rb +0 -25
  349. data/lib/karafka/params/params_batch.rb +0 -60
  350. data/lib/karafka/patches/ruby_kafka.rb +0 -47
  351. data/lib/karafka/persistence/client.rb +0 -29
  352. data/lib/karafka/persistence/consumers.rb +0 -45
  353. data/lib/karafka/persistence/topics.rb +0 -48
  354. data/lib/karafka/responders/builder.rb +0 -36
  355. data/lib/karafka/responders/topic.rb +0 -55
  356. data/lib/karafka/routing/topic_mapper.rb +0 -53
  357. data/lib/karafka/serialization/json/serializer.rb +0 -31
  358. data/lib/karafka/setup/configurators/water_drop.rb +0 -36
  359. data/lib/karafka/templates/application_responder.rb.erb +0 -11
@@ -4,54 +4,285 @@
4
4
  module Karafka
5
5
  # Base consumer from which all Karafka consumers should inherit
6
6
  class BaseConsumer
7
+ # Allow for consumer instance tagging for instrumentation
8
+ include ::Karafka::Core::Taggable
9
+
7
10
  extend Forwardable
8
11
 
9
- # Allows us to mark messages as consumed for non-automatic mode without having
10
- # to use consumer client directly. We do this that way, because most of the people should not
11
- # mess with the client instance directly (just in case)
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
12
+ def_delegators :@coordinator, :topic, :partition
13
+
14
+ # @return [String] id of the current consumer
15
+ attr_reader :id
16
+ # @return [Karafka::Routing::Topic] topic to which a given consumer is subscribed
17
+ attr_accessor :messages
18
+ # @return [Karafka::Connection::Client] kafka connection client
19
+ attr_accessor :client
20
+ # @return [Karafka::Processing::Coordinator] coordinator
21
+ attr_accessor :coordinator
22
+ # @return [Waterdrop::Producer] producer instance
23
+ attr_accessor :producer
24
+
25
+ # Creates new consumer and assigns it an id
26
+ def initialize
27
+ @id = SecureRandom.hex(6)
28
+ @used = false
29
+ end
19
30
 
20
- private delegated_method_name
31
+ # Can be used to run preparation code prior to the job being enqueued
32
+ #
33
+ # @private
34
+ # @note This should not be used by the end users as it is part of the lifecycle of things and
35
+ # not as a part of the public api. This should not perform any extensive operations as it is
36
+ # blocking and running in the listener thread.
37
+ def on_before_enqueue
38
+ @used = true
39
+ handle_before_enqueue
40
+ rescue StandardError => e
41
+ Karafka.monitor.instrument(
42
+ 'error.occurred',
43
+ error: e,
44
+ caller: self,
45
+ type: 'consumer.before_enqueue.error'
46
+ )
21
47
  end
22
48
 
23
- # @return [Karafka::Routing::Topic] topic to which a given consumer is subscribed
24
- attr_reader :topic
25
- # @return [Karafka::Params:ParamsBatch] current params batch
26
- attr_accessor :params_batch
49
+ # Can be used to run preparation code in the worker
50
+ #
51
+ # @private
52
+ # @note This should not be used by the end users as it is part of the lifecycle of things and
53
+ # not as part of the public api. This can act as a hook when creating non-blocking
54
+ # consumers and doing other advanced stuff
55
+ def on_before_consume
56
+ messages.metadata.processed_at = Time.now
57
+ messages.metadata.freeze
27
58
 
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)
59
+ # We run this after the full metadata setup, so we can use all the messages information
60
+ # if needed
61
+ handle_before_consume
62
+ rescue StandardError => e
63
+ Karafka.monitor.instrument(
64
+ 'error.occurred',
65
+ error: e,
66
+ caller: self,
67
+ type: 'consumer.before_consume.error'
68
+ )
34
69
  end
35
70
 
36
71
  # Executes the default consumer flow.
37
- def call
38
- process
72
+ #
73
+ # @private
74
+ #
75
+ # @return [Boolean] true if there was no exception, otherwise false.
76
+ #
77
+ # @note We keep the seek offset tracking, and use it to compensate for async offset flushing
78
+ # that may not yet kick in when error occurs. That way we pause always on the last processed
79
+ # message.
80
+ def on_consume
81
+ handle_consume
82
+ rescue StandardError => e
83
+ Karafka.monitor.instrument(
84
+ 'error.occurred',
85
+ error: e,
86
+ caller: self,
87
+ seek_offset: coordinator.seek_offset,
88
+ type: 'consumer.consume.error'
89
+ )
39
90
  end
40
91
 
41
- private
92
+ # @private
93
+ # @note This should not be used by the end users as it is part of the lifecycle of things but
94
+ # not as part of the public api.
95
+ def on_after_consume
96
+ handle_after_consume
97
+ rescue StandardError => e
98
+ Karafka.monitor.instrument(
99
+ 'error.occurred',
100
+ error: e,
101
+ caller: self,
102
+ type: 'consumer.after_consume.error'
103
+ )
104
+ end
42
105
 
43
- # @return [Karafka::Connection::Client] messages consuming client that can be used to
44
- # commit manually offset or pause / stop consumer based on the business logic
45
- def client
46
- Persistence::Client.read
106
+ # Trigger method for running on idle runs without messages
107
+ #
108
+ # @private
109
+ def on_idle
110
+ handle_idle
111
+ rescue StandardError => e
112
+ Karafka.monitor.instrument(
113
+ 'error.occurred',
114
+ error: e,
115
+ caller: self,
116
+ type: 'consumer.idle.error'
117
+ )
47
118
  end
48
119
 
120
+ # Trigger method for running on partition revocation.
121
+ #
122
+ # @private
123
+ def on_revoked
124
+ handle_revoked
125
+ rescue StandardError => e
126
+ Karafka.monitor.instrument(
127
+ 'error.occurred',
128
+ error: e,
129
+ caller: self,
130
+ type: 'consumer.revoked.error'
131
+ )
132
+ end
133
+
134
+ # Trigger method for running on shutdown.
135
+ #
136
+ # @private
137
+ def on_shutdown
138
+ handle_shutdown
139
+ rescue StandardError => e
140
+ Karafka.monitor.instrument(
141
+ 'error.occurred',
142
+ error: e,
143
+ caller: self,
144
+ type: 'consumer.shutdown.error'
145
+ )
146
+ end
147
+
148
+ private
149
+
49
150
  # Method that will perform business logic and on data received from Kafka (it will consume
50
151
  # the data)
51
- # @note This method needs bo be implemented in a subclass. We stub it here as a failover if
152
+ # @note This method needs to be implemented in a subclass. We stub it here as a failover if
52
153
  # someone forgets about it or makes on with typo
53
154
  def consume
54
155
  raise NotImplementedError, 'Implement this in a subclass'
55
156
  end
157
+
158
+ # Method that will be executed when a given topic partition is revoked. You can use it for
159
+ # some teardown procedures (closing file handler, etc).
160
+ def revoked; end
161
+
162
+ # Method that will be executed when the process is shutting down. You can use it for
163
+ # some teardown procedures (closing file handler, etc).
164
+ def shutdown; end
165
+
166
+ # @return [Boolean] was this consumer in active use. Active use means running `#consume` at
167
+ # least once. Consumer may have to run `#revoked` or `#shutdown` despite not running
168
+ # `#consume` previously in delayed job cases and other cases that potentially involve running
169
+ # the `Jobs::Idle` for house-keeping
170
+ def used?
171
+ @used
172
+ end
173
+
174
+ # Pauses processing on a given offset or consecutive offset for the current topic partition
175
+ #
176
+ # After given partition is resumed, it will continue processing from the given offset
177
+ # @param offset [Integer, Symbol] offset from which we want to restart the processing or
178
+ # `:consecutive` if we want to pause and continue without changing the consecutive offset
179
+ # (cursor position)
180
+ # @param timeout [Integer, nil] how long in milliseconds do we want to pause or nil to use the
181
+ # default exponential pausing strategy defined for retries
182
+ # @param manual_pause [Boolean] Flag to differentiate between user pause and system/strategy
183
+ # based pause. While they both pause in exactly the same way, the strategy application
184
+ # may need to differentiate between them.
185
+ #
186
+ # @note It is **critical** to understand how pause with `:consecutive` offset operates. While
187
+ # it provides benefit of not purging librdkafka buffer, in case of usage of filters, retries
188
+ # or other advanced options the consecutive offset may not be the one you want to pause on.
189
+ # Test it well to ensure, that this behaviour is expected by you.
190
+ def pause(offset, timeout = nil, manual_pause = true)
191
+ timeout ? coordinator.pause_tracker.pause(timeout) : coordinator.pause_tracker.pause
192
+
193
+ offset = nil if offset == :consecutive
194
+
195
+ client.pause(topic.name, partition, offset)
196
+
197
+ # Indicate, that user took a manual action of pausing
198
+ coordinator.manual_pause if manual_pause
199
+
200
+ Karafka.monitor.instrument(
201
+ 'consumer.consuming.pause',
202
+ caller: self,
203
+ manual: manual_pause,
204
+ topic: topic.name,
205
+ partition: partition,
206
+ subscription_group: topic.subscription_group,
207
+ offset: offset,
208
+ timeout: coordinator.pause_tracker.current_timeout,
209
+ attempt: coordinator.pause_tracker.attempt
210
+ )
211
+ end
212
+
213
+ # Resumes processing of the current topic partition
214
+ def resume
215
+ return unless coordinator.pause_tracker.paused?
216
+
217
+ # This is sufficient to expire a partition pause, as with it will be resumed by the listener
218
+ # thread before the next poll.
219
+ coordinator.pause_tracker.expire
220
+ end
221
+
222
+ # Seeks in the context of current topic and partition
223
+ #
224
+ # @param offset [Integer, Time] offset where we want to seek or time of the offset where we
225
+ # want to seek.
226
+ # @param manual_seek [Boolean] Flag to differentiate between user seek and system/strategy
227
+ # based seek. User seek operations should take precedence over system actions, hence we need
228
+ # to know who invoked it.
229
+ # @note Please note, that if you are seeking to a time offset, getting the offset is blocking
230
+ def seek(offset, manual_seek = true)
231
+ coordinator.manual_seek if manual_seek
232
+
233
+ client.seek(
234
+ Karafka::Messages::Seek.new(
235
+ topic.name,
236
+ partition,
237
+ offset
238
+ )
239
+ )
240
+ end
241
+
242
+ # @return [Boolean] true if partition was revoked from the current consumer
243
+ # @note There are two "levels" on which we can know that partition was revoked. First one is
244
+ # when we loose the assignment involuntarily and second is when coordinator gets this info
245
+ # after we poll with the rebalance callbacks. The first check allows us to get this notion
246
+ # even before we poll but it gets reset when polling happens, hence we also need to switch
247
+ # the coordinator state after the revocation (but prior to running more jobs)
248
+ def revoked?
249
+ return true if coordinator.revoked?
250
+ return false unless client.assignment_lost?
251
+
252
+ coordinator.revoke
253
+
254
+ true
255
+ end
256
+
257
+ # @return [Boolean] are we retrying processing after an error. This can be used to provide a
258
+ # different flow after there is an error, for example for resources cleanup, small manual
259
+ # backoff or different instrumentation tracking.
260
+ def retrying?
261
+ attempt > 1
262
+ end
263
+
264
+ # @return [Integer] attempt of processing given batch. 1 if this is the first attempt or higher
265
+ # in case it is a retry
266
+ def attempt
267
+ coordinator.pause_tracker.attempt
268
+ end
269
+
270
+ # Pauses the processing from the last offset to retry on given message
271
+ # @private
272
+ def retry_after_pause
273
+ pause(coordinator.seek_offset, nil, false)
274
+
275
+ # Instrumentation needs to run **after** `#pause` invocation because we rely on the states
276
+ # set by `#pause`
277
+ Karafka.monitor.instrument(
278
+ 'consumer.consuming.retry',
279
+ caller: self,
280
+ topic: topic.name,
281
+ partition: partition,
282
+ offset: coordinator.seek_offset,
283
+ timeout: coordinator.pause_tracker.current_timeout,
284
+ attempt: coordinator.pause_tracker.attempt
285
+ )
286
+ end
56
287
  end
57
288
  end
@@ -1,31 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Karafka
4
- class Cli < Thor
4
+ class Cli
5
5
  # Base class for all the command that we want to define
6
- # This base class provides a nicer interface to Thor and allows to easier separate single
7
- # independent commands
8
- # In order to define a new command you need to:
9
- # - specify its desc
10
- # - implement call method
11
- #
12
- # @example Create a dummy command
13
- # class Dummy < Base
14
- # self.desc = 'Dummy command'
15
- #
16
- # def call
17
- # puts 'I'm doing nothing!
18
- # end
19
- # end
6
+ # This base class provides an interface to easier separate single independent commands
20
7
  class Base
21
- include Thor::Shell
8
+ # @return [Hash] given command cli options
9
+ attr_reader :options
22
10
 
23
- # We can use it to call other cli methods via this object
24
- attr_reader :cli
25
-
26
- # @param cli [Karafka::Cli] current Karafka Cli instance
27
- def initialize(cli)
28
- @cli = cli
11
+ # Creates new CLI command instance
12
+ def initialize
13
+ # Parses the given command CLI options
14
+ @options = self.class.parse_options
29
15
  end
30
16
 
31
17
  # This method should implement proper cli action
@@ -34,6 +20,26 @@ module Karafka
34
20
  end
35
21
 
36
22
  class << self
23
+ # Loads proper environment with what is needed to run the CLI
24
+ def load
25
+ # If there is a boot file, we need to require it as we expect it to contain
26
+ # Karafka app setup, routes, etc
27
+ if File.exist?(::Karafka.boot_file)
28
+ rails_env_rb = File.join(Dir.pwd, 'config/environment.rb')
29
+
30
+ # Load Rails environment file that starts Rails, so we can reference consumers and
31
+ # other things from `karafka.rb` file. This will work only for Rails, for non-rails
32
+ # a manual setup is needed
33
+ require rails_env_rb if Kernel.const_defined?(:Rails) && File.exist?(rails_env_rb)
34
+
35
+ require Karafka.boot_file.to_s
36
+ # However when it is unavailable, we still want to be able to run help command
37
+ # and install command as they don't require configured app itself to run
38
+ elsif %w[-h install].none? { |cmd| cmd == ARGV[0] }
39
+ raise ::Karafka::Errors::MissingBootFileError, ::Karafka.boot_file
40
+ end
41
+ end
42
+
37
43
  # Allows to set options for Thor cli
38
44
  # @see https://github.com/erikhuda/thor
39
45
  # @param option Single option details
@@ -43,27 +49,47 @@ module Karafka
43
49
  end
44
50
 
45
51
  # Allows to set description of a given cli command
46
- # @param args [Array] All the arguments that Thor desc method accepts
47
- def desc(*args)
48
- @desc ||= args
52
+ # @param desc [String] Description of a given cli command
53
+ def desc(desc = nil)
54
+ @desc ||= desc
49
55
  end
50
56
 
51
- # This method will bind a given Cli command into Karafka Cli
52
- # This method is a wrapper to way Thor defines its commands
53
- # @param cli_class [Karafka::Cli] Karafka cli_class
54
- def bind_to(cli_class)
55
- cli_class.desc name, *@desc
57
+ # Allows to set aliases for a given cli command
58
+ # @param args [Array] list of aliases that we can use to run given cli command
59
+ def aliases(*args)
60
+ @aliases ||= []
61
+ @aliases << args.map(&:to_s)
62
+ end
56
63
 
57
- (@options || []).each { |option| cli_class.option(*option) }
64
+ # Parses the CLI options
65
+ # @return [Hash] hash with parsed values
66
+ def parse_options
67
+ options = {}
58
68
 
59
- context = self
69
+ OptionParser.new do |opts|
70
+ (@options || []).each do |option|
71
+ # Creates aliases for backwards compatibility
72
+ names = option[3].flat_map { |name| [name, name.tr('_', '-')] }
73
+ names.map! { |name| "#{name} value1,value2,valueN" } if option[2] == Array
74
+ names.uniq!
60
75
 
61
- cli_class.send :define_method, name do |*args|
62
- context.new(self).call(*args)
63
- end
76
+ opts.on(
77
+ *[names, option[2], option[1]].flatten
78
+ ) { |value| options[option[0]] = value }
79
+ end
80
+ end.parse!
81
+
82
+ options
64
83
  end
65
84
 
66
- private
85
+ # @return [Array<Class>] available commands
86
+ def commands
87
+ ObjectSpace
88
+ .each_object(Class)
89
+ .select { |klass| klass.superclass == Karafka::Cli::Base }
90
+ .reject { |klass| klass.to_s.end_with?('::Base') }
91
+ .sort_by(&:name)
92
+ end
67
93
 
68
94
  # @return [String] downcased current class name that we use to define name for
69
95
  # given Cli command
@@ -72,6 +98,11 @@ module Karafka
72
98
  def name
73
99
  to_s.split('::').last.downcase
74
100
  end
101
+
102
+ # @return [Array<String>] names and aliases for command matching
103
+ def names
104
+ ((@aliases || []) << name).flatten.map(&:to_s)
105
+ end
75
106
  end
76
107
  end
77
108
  end
@@ -2,29 +2,35 @@
2
2
 
3
3
  module Karafka
4
4
  # Karafka framework Cli
5
- class Cli < Thor
5
+ class Cli
6
6
  # Console Karafka Cli action
7
7
  class Console < Base
8
- desc 'Start the Karafka console (short-cut alias: "c")'
9
- option aliases: 'c'
8
+ desc 'Starts the Karafka console (short-cut alias: "c")'
9
+
10
+ aliases :c
10
11
 
11
12
  class << self
12
- # @return [String] Console executing command
13
+ # @return [String] Console executing command for non-Rails setup
13
14
  # @example
14
15
  # 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}"
16
+ def console
17
+ "IRBRC='#{Karafka.gem_root}/.console_irbrc' bundle exec irb -r #{Karafka.boot_file}"
18
+ end
19
+
20
+ # @return [String] Console executing command for Rails setup
21
+ # @note In case of Rails, it has its own console, hence we can just defer to it
22
+ def rails_console
23
+ 'bundle exec rails console'
21
24
  end
22
25
  end
23
26
 
24
27
  # Start the Karafka console
25
28
  def call
26
- cli.info
27
- exec self.class.command
29
+ Info.new.call
30
+
31
+ command = ::Karafka.rails? ? self.class.rails_console : self.class.console
32
+
33
+ exec "KARAFKA_CONSOLE=true #{command}"
28
34
  end
29
35
  end
30
36
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ # Karafka framework Cli
5
+ class Cli
6
+ # Prints info with list of commands available
7
+ class Help < Base
8
+ desc 'Describes available commands'
9
+
10
+ # Print available commands
11
+ def call
12
+ # Find the longest command for alignment purposes
13
+ max_command_length = self.class.commands.map(&:name).map(&:size).max
14
+
15
+ puts 'Karafka commands:'
16
+
17
+ # Print each command formatted with its description
18
+ self.class.commands.each do |command|
19
+ puts " #{command.name.ljust(max_command_length)} # #{command.desc}"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,29 +2,64 @@
2
2
 
3
3
  module Karafka
4
4
  # Karafka framework Cli
5
- class Cli < Thor
5
+ class Cli
6
6
  # Info Karafka Cli action
7
7
  class Info < Base
8
- desc 'Print configuration details and other options of your application'
8
+ desc 'Prints configuration details and other options of your application'
9
+
10
+ # Nice karafka banner
11
+ BANNER = <<~BANNER
12
+
13
+ @@@ @@@@@ @@@
14
+ @@@ @@@ @@@
15
+ @@@ @@@ @@@@@@@@@ @@@ @@@ @@@@@@@@@ @@@@@@@@ @@@ @@@@ @@@@@@@@@
16
+ @@@@@@ @@@ @@@ @@@@@ @@@ @@@ @@@ @@@@@@@ @@@ @@@
17
+ @@@@@@@ @@@ @@@ @@@ @@@@ @@@ @@@ @@@@@@@ @@@ @@@
18
+ @@@ @@@@ @@@@@@@@@@ @@@ @@@@@@@@@@ @@@ @@@ @@@@ @@@@@@@@@@
19
+
20
+ BANNER
9
21
 
10
22
  # Print configuration details and other options of your application
11
23
  def call
24
+ Karafka.logger.info(BANNER)
25
+ Karafka.logger.info((core_info + license_info).join("\n"))
26
+ end
27
+
28
+ private
29
+
30
+ # @return [Array<String>] core framework related info
31
+ def core_info
12
32
  config = Karafka::App.config
13
33
 
14
- info = [
15
- "Karafka version: #{Karafka::VERSION}",
16
- "Ruby version: #{RUBY_VERSION}",
17
- "Ruby-kafka version: #{::Kafka::VERSION}",
34
+ postfix = Karafka.pro? ? ' + Pro' : ''
35
+
36
+ [
37
+ "Karafka version: #{Karafka::VERSION}#{postfix}",
38
+ "Ruby version: #{RUBY_DESCRIPTION}",
39
+ "Rdkafka version: #{::Rdkafka::VERSION}",
40
+ "Consumer groups count: #{Karafka::App.consumer_groups.size}",
41
+ "Subscription groups count: #{Karafka::App.subscription_groups.values.flatten.size}",
42
+ "Workers count: #{Karafka::App.config.concurrency}",
18
43
  "Application client id: #{config.client_id}",
19
- "Backend: #{config.backend}",
20
- "Batch fetching: #{config.batch_fetching}",
21
- "Batch consuming: #{config.batch_consuming}",
22
44
  "Boot file: #{Karafka.boot_file}",
23
- "Environment: #{Karafka.env}",
24
- "Kafka seed brokers: #{config.kafka.seed_brokers}"
45
+ "Environment: #{Karafka.env}"
25
46
  ]
47
+ end
48
+
49
+ # @return [Array<String>] license related info
50
+ def license_info
51
+ config = Karafka::App.config
26
52
 
27
- Karafka.logger.info(info.join("\n"))
53
+ if Karafka.pro?
54
+ [
55
+ 'License: Commercial',
56
+ "License entity: #{config.license.entity}"
57
+ ]
58
+ else
59
+ [
60
+ 'License: LGPL-3.0'
61
+ ]
62
+ end
28
63
  end
29
64
  end
30
65
  end
@@ -4,37 +4,37 @@ require 'erb'
4
4
 
5
5
  module Karafka
6
6
  # Karafka framework Cli
7
- class Cli < Thor
7
+ class Cli
8
8
  # Install Karafka Cli action
9
9
  class Install < Base
10
- desc 'Install all required things for Karafka application in current directory'
10
+ include Helpers::Colorize
11
+
12
+ desc 'Installs all required things for Karafka application in current directory'
11
13
 
12
14
  # Directories created by default
13
15
  INSTALL_DIRS = %w[
14
16
  app/consumers
15
- app/responders
16
- app/workers
17
17
  config
18
- lib
19
18
  log
20
- tmp/pids
19
+ lib
21
20
  ].freeze
22
21
 
23
22
  # Where should we map proper files from templates
24
23
  INSTALL_FILES_MAP = {
25
24
  'karafka.rb.erb' => Karafka.boot_file.basename,
26
25
  'application_consumer.rb.erb' => 'app/consumers/application_consumer.rb',
27
- 'application_responder.rb.erb' => 'app/responders/application_responder.rb'
26
+ 'example_consumer.rb.erb' => 'app/consumers/example_consumer.rb'
28
27
  }.freeze
29
28
 
30
- # @param args [Array] all the things that Thor CLI accepts
31
- def initialize(*args)
29
+ def initialize
32
30
  super
31
+
33
32
  dependencies = Bundler::LockfileParser.new(
34
33
  Bundler.read_file(
35
34
  Bundler.default_lockfile
36
35
  )
37
36
  ).dependencies
37
+
38
38
  @rails = dependencies.key?('railties') || dependencies.key?('rails')
39
39
  end
40
40
 
@@ -44,16 +44,25 @@ module Karafka
44
44
  FileUtils.mkdir_p Karafka.root.join(dir)
45
45
  end
46
46
 
47
+ puts
48
+ puts 'Installing Karafka framework...'
49
+ puts 'Ruby on Rails detected...' if rails?
50
+ puts
51
+
47
52
  INSTALL_FILES_MAP.each do |source, target|
48
- target = Karafka.root.join(target)
53
+ pathed_target = Karafka.root.join(target)
49
54
 
50
55
  template = File.read(Karafka.core_root.join("templates/#{source}"))
51
- # @todo Replace with the keyword argument version once we don't have to support
52
- # Ruby < 2.6
53
- render = ::ERB.new(template, nil, '-').result(binding)
56
+ render = ::ERB.new(template, trim_mode: '-').result(binding)
54
57
 
55
- File.open(target, 'w') { |file| file.write(render) }
58
+ File.open(pathed_target, 'w') { |file| file.write(render) }
59
+
60
+ puts "#{green('Created')} #{target}"
56
61
  end
62
+
63
+ puts
64
+ puts("Installation #{green('completed')}. Have fun!")
65
+ puts
57
66
  end
58
67
 
59
68
  # @return [Boolean] true if we have Rails loaded