karafka 1.4.12 → 2.2.10
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/.github/FUNDING.yml +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +10 -9
- data/.github/workflows/ci.yml +169 -31
- data/.rspec +4 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +716 -607
- data/CONTRIBUTING.md +10 -19
- data/Gemfile +7 -0
- data/Gemfile.lock +69 -92
- data/LICENSE +17 -0
- data/LICENSE-COMM +89 -0
- data/LICENSE-LGPL +165 -0
- data/README.md +48 -47
- data/bin/benchmarks +99 -0
- data/bin/create_token +22 -0
- data/bin/integrations +310 -0
- data/bin/karafka +5 -14
- data/bin/record_rss +50 -0
- data/bin/rspecs +6 -0
- data/bin/scenario +29 -0
- data/bin/stress_many +13 -0
- data/bin/stress_one +13 -0
- data/bin/verify_license_integrity +37 -0
- data/bin/wait_for_kafka +24 -0
- data/certs/cert_chain.pem +26 -0
- data/certs/karafka-pro.pem +11 -0
- data/config/locales/errors.yml +97 -0
- data/config/locales/pro_errors.yml +59 -0
- data/docker-compose.yml +19 -11
- data/karafka.gemspec +26 -22
- data/lib/active_job/karafka.rb +17 -0
- data/lib/active_job/queue_adapters/karafka_adapter.rb +32 -0
- data/lib/karafka/active_job/consumer.rb +49 -0
- data/lib/karafka/active_job/current_attributes/loading.rb +36 -0
- data/lib/karafka/active_job/current_attributes/persistence.rb +28 -0
- data/lib/karafka/active_job/current_attributes.rb +42 -0
- data/lib/karafka/active_job/dispatcher.rb +69 -0
- data/lib/karafka/active_job/job_extensions.rb +34 -0
- data/lib/karafka/active_job/job_options_contract.rb +32 -0
- data/lib/karafka/admin.rb +313 -0
- data/lib/karafka/app.rb +47 -23
- data/lib/karafka/base_consumer.rb +260 -29
- data/lib/karafka/cli/base.rb +67 -36
- data/lib/karafka/cli/console.rb +18 -12
- data/lib/karafka/cli/help.rb +24 -0
- data/lib/karafka/cli/info.rb +47 -12
- data/lib/karafka/cli/install.rb +23 -14
- data/lib/karafka/cli/server.rb +101 -44
- data/lib/karafka/cli/topics.rb +146 -0
- data/lib/karafka/cli.rb +24 -27
- data/lib/karafka/connection/client.rb +553 -90
- data/lib/karafka/connection/consumer_group_coordinator.rb +48 -0
- data/lib/karafka/connection/listener.rb +294 -38
- data/lib/karafka/connection/listeners_batch.rb +40 -0
- data/lib/karafka/connection/messages_buffer.rb +84 -0
- data/lib/karafka/connection/pauses_manager.rb +46 -0
- data/lib/karafka/connection/proxy.rb +98 -0
- data/lib/karafka/connection/raw_messages_buffer.rb +101 -0
- data/lib/karafka/connection/rebalance_manager.rb +105 -0
- data/lib/karafka/contracts/base.rb +17 -0
- data/lib/karafka/contracts/config.rb +130 -11
- data/lib/karafka/contracts/consumer_group.rb +32 -187
- data/lib/karafka/contracts/server_cli_options.rb +80 -19
- data/lib/karafka/contracts/topic.rb +65 -0
- data/lib/karafka/contracts.rb +1 -1
- data/lib/karafka/embedded.rb +36 -0
- data/lib/karafka/env.rb +46 -0
- data/lib/karafka/errors.rb +37 -21
- data/lib/karafka/helpers/async.rb +33 -0
- data/lib/karafka/helpers/colorize.rb +26 -0
- data/lib/karafka/helpers/multi_delegator.rb +2 -2
- data/lib/karafka/instrumentation/callbacks/error.rb +39 -0
- data/lib/karafka/instrumentation/callbacks/rebalance.rb +64 -0
- data/lib/karafka/instrumentation/callbacks/statistics.rb +51 -0
- data/lib/karafka/instrumentation/logger_listener.rb +303 -0
- data/lib/karafka/instrumentation/monitor.rb +13 -61
- data/lib/karafka/instrumentation/notifications.rb +79 -0
- data/lib/karafka/instrumentation/proctitle_listener.rb +7 -16
- data/lib/karafka/instrumentation/vendors/appsignal/base.rb +30 -0
- data/lib/karafka/instrumentation/vendors/appsignal/client.rb +122 -0
- data/lib/karafka/instrumentation/vendors/appsignal/dashboard.json +222 -0
- data/lib/karafka/instrumentation/vendors/appsignal/errors_listener.rb +30 -0
- data/lib/karafka/instrumentation/vendors/appsignal/metrics_listener.rb +331 -0
- data/lib/karafka/instrumentation/vendors/datadog/dashboard.json +1 -0
- data/lib/karafka/instrumentation/vendors/datadog/logger_listener.rb +155 -0
- data/lib/karafka/instrumentation/vendors/datadog/metrics_listener.rb +264 -0
- data/lib/karafka/instrumentation/vendors/kubernetes/liveness_listener.rb +176 -0
- data/lib/karafka/licenser.rb +78 -0
- data/lib/karafka/messages/batch_metadata.rb +52 -0
- data/lib/karafka/messages/builders/batch_metadata.rb +60 -0
- data/lib/karafka/messages/builders/message.rb +40 -0
- data/lib/karafka/messages/builders/messages.rb +36 -0
- data/lib/karafka/{params/params.rb → messages/message.rb} +20 -13
- data/lib/karafka/messages/messages.rb +71 -0
- data/lib/karafka/{params → messages}/metadata.rb +4 -6
- data/lib/karafka/messages/parser.rb +14 -0
- data/lib/karafka/messages/seek.rb +12 -0
- data/lib/karafka/patches/rdkafka/bindings.rb +122 -0
- data/lib/karafka/patches/rdkafka/opaque.rb +36 -0
- data/lib/karafka/pro/active_job/consumer.rb +47 -0
- data/lib/karafka/pro/active_job/dispatcher.rb +86 -0
- data/lib/karafka/pro/active_job/job_options_contract.rb +45 -0
- data/lib/karafka/pro/cleaner/errors.rb +27 -0
- data/lib/karafka/pro/cleaner/messages/message.rb +46 -0
- data/lib/karafka/pro/cleaner/messages/messages.rb +42 -0
- data/lib/karafka/pro/cleaner.rb +41 -0
- data/lib/karafka/pro/contracts/base.rb +23 -0
- data/lib/karafka/pro/contracts/server_cli_options.rb +111 -0
- data/lib/karafka/pro/encryption/cipher.rb +58 -0
- data/lib/karafka/pro/encryption/contracts/config.rb +79 -0
- data/lib/karafka/pro/encryption/errors.rb +27 -0
- data/lib/karafka/pro/encryption/messages/middleware.rb +46 -0
- data/lib/karafka/pro/encryption/messages/parser.rb +56 -0
- data/lib/karafka/pro/encryption/setup/config.rb +48 -0
- data/lib/karafka/pro/encryption.rb +47 -0
- data/lib/karafka/pro/iterator/expander.rb +95 -0
- data/lib/karafka/pro/iterator/tpl_builder.rb +155 -0
- data/lib/karafka/pro/iterator.rb +170 -0
- data/lib/karafka/pro/loader.rb +106 -0
- data/lib/karafka/pro/performance_tracker.rb +84 -0
- data/lib/karafka/pro/processing/collapser.rb +62 -0
- data/lib/karafka/pro/processing/coordinator.rb +147 -0
- data/lib/karafka/pro/processing/filters/base.rb +61 -0
- data/lib/karafka/pro/processing/filters/delayer.rb +70 -0
- data/lib/karafka/pro/processing/filters/expirer.rb +51 -0
- data/lib/karafka/pro/processing/filters/inline_insights_delayer.rb +78 -0
- data/lib/karafka/pro/processing/filters/throttler.rb +84 -0
- data/lib/karafka/pro/processing/filters/virtual_limiter.rb +52 -0
- data/lib/karafka/pro/processing/filters_applier.rb +105 -0
- data/lib/karafka/pro/processing/jobs/consume_non_blocking.rb +39 -0
- data/lib/karafka/pro/processing/jobs/revoked_non_blocking.rb +37 -0
- data/lib/karafka/pro/processing/jobs_builder.rb +50 -0
- data/lib/karafka/pro/processing/partitioner.rb +69 -0
- data/lib/karafka/pro/processing/scheduler.rb +75 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom.rb +70 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom_vp.rb +76 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom.rb +72 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom_vp.rb +76 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom.rb +66 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom_vp.rb +70 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_mom.rb +64 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_mom_vp.rb +69 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom.rb +38 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom_vp.rb +66 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_mom.rb +38 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_mom_vp.rb +58 -0
- data/lib/karafka/pro/processing/strategies/aj/lrj_mom.rb +37 -0
- data/lib/karafka/pro/processing/strategies/aj/lrj_mom_vp.rb +82 -0
- data/lib/karafka/pro/processing/strategies/aj/mom.rb +36 -0
- data/lib/karafka/pro/processing/strategies/aj/mom_vp.rb +52 -0
- data/lib/karafka/pro/processing/strategies/base.rb +26 -0
- data/lib/karafka/pro/processing/strategies/default.rb +105 -0
- data/lib/karafka/pro/processing/strategies/dlq/default.rb +137 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr.rb +61 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj.rb +75 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom.rb +71 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom_vp.rb +43 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_vp.rb +41 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_mom.rb +69 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_mom_vp.rb +41 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj.rb +64 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj_mom.rb +65 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj_mom_vp.rb +36 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj_vp.rb +39 -0
- data/lib/karafka/pro/processing/strategies/dlq/mom.rb +68 -0
- data/lib/karafka/pro/processing/strategies/dlq/mom_vp.rb +37 -0
- data/lib/karafka/pro/processing/strategies/dlq/vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/ftr/default.rb +111 -0
- data/lib/karafka/pro/processing/strategies/ftr/vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/lrj/default.rb +85 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr.rb +69 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr_mom.rb +67 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr_mom_vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr_vp.rb +39 -0
- data/lib/karafka/pro/processing/strategies/lrj/mom.rb +77 -0
- data/lib/karafka/pro/processing/strategies/lrj/mom_vp.rb +38 -0
- data/lib/karafka/pro/processing/strategies/lrj/vp.rb +36 -0
- data/lib/karafka/pro/processing/strategies/mom/default.rb +46 -0
- data/lib/karafka/pro/processing/strategies/mom/ftr.rb +53 -0
- data/lib/karafka/pro/processing/strategies/mom/ftr_vp.rb +37 -0
- data/lib/karafka/pro/processing/strategies/mom/vp.rb +35 -0
- data/lib/karafka/pro/processing/strategies/vp/default.rb +124 -0
- data/lib/karafka/pro/processing/strategies.rb +22 -0
- data/lib/karafka/pro/processing/strategy_selector.rb +84 -0
- data/lib/karafka/pro/processing/virtual_offset_manager.rb +147 -0
- data/lib/karafka/pro/routing/features/active_job/builder.rb +45 -0
- data/lib/karafka/pro/routing/features/active_job.rb +26 -0
- data/lib/karafka/pro/routing/features/base.rb +24 -0
- data/lib/karafka/pro/routing/features/dead_letter_queue/contracts/topic.rb +53 -0
- data/lib/karafka/pro/routing/features/dead_letter_queue.rb +27 -0
- data/lib/karafka/pro/routing/features/delaying/config.rb +27 -0
- data/lib/karafka/pro/routing/features/delaying/contracts/topic.rb +41 -0
- data/lib/karafka/pro/routing/features/delaying/topic.rb +59 -0
- data/lib/karafka/pro/routing/features/delaying.rb +29 -0
- data/lib/karafka/pro/routing/features/expiring/config.rb +27 -0
- data/lib/karafka/pro/routing/features/expiring/contracts/topic.rb +41 -0
- data/lib/karafka/pro/routing/features/expiring/topic.rb +59 -0
- data/lib/karafka/pro/routing/features/expiring.rb +27 -0
- data/lib/karafka/pro/routing/features/filtering/config.rb +40 -0
- data/lib/karafka/pro/routing/features/filtering/contracts/topic.rb +44 -0
- data/lib/karafka/pro/routing/features/filtering/topic.rb +51 -0
- data/lib/karafka/pro/routing/features/filtering.rb +27 -0
- data/lib/karafka/pro/routing/features/inline_insights/config.rb +32 -0
- data/lib/karafka/pro/routing/features/inline_insights/contracts/topic.rb +41 -0
- data/lib/karafka/pro/routing/features/inline_insights/topic.rb +52 -0
- data/lib/karafka/pro/routing/features/inline_insights.rb +26 -0
- data/lib/karafka/pro/routing/features/long_running_job/config.rb +28 -0
- data/lib/karafka/pro/routing/features/long_running_job/contracts/topic.rb +40 -0
- data/lib/karafka/pro/routing/features/long_running_job/topic.rb +42 -0
- data/lib/karafka/pro/routing/features/long_running_job.rb +28 -0
- data/lib/karafka/pro/routing/features/patterns/builder.rb +38 -0
- data/lib/karafka/pro/routing/features/patterns/config.rb +54 -0
- data/lib/karafka/pro/routing/features/patterns/consumer_group.rb +72 -0
- data/lib/karafka/pro/routing/features/patterns/contracts/consumer_group.rb +62 -0
- data/lib/karafka/pro/routing/features/patterns/contracts/pattern.rb +46 -0
- data/lib/karafka/pro/routing/features/patterns/contracts/topic.rb +41 -0
- data/lib/karafka/pro/routing/features/patterns/detector.rb +71 -0
- data/lib/karafka/pro/routing/features/patterns/pattern.rb +95 -0
- data/lib/karafka/pro/routing/features/patterns/patterns.rb +35 -0
- data/lib/karafka/pro/routing/features/patterns/topic.rb +50 -0
- data/lib/karafka/pro/routing/features/patterns/topics.rb +53 -0
- data/lib/karafka/pro/routing/features/patterns.rb +33 -0
- data/lib/karafka/pro/routing/features/pausing/contracts/topic.rb +51 -0
- data/lib/karafka/pro/routing/features/pausing/topic.rb +44 -0
- data/lib/karafka/pro/routing/features/pausing.rb +25 -0
- data/lib/karafka/pro/routing/features/throttling/config.rb +32 -0
- data/lib/karafka/pro/routing/features/throttling/contracts/topic.rb +44 -0
- data/lib/karafka/pro/routing/features/throttling/topic.rb +69 -0
- data/lib/karafka/pro/routing/features/throttling.rb +30 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/config.rb +30 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/contracts/topic.rb +55 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/topic.rb +56 -0
- data/lib/karafka/pro/routing/features/virtual_partitions.rb +27 -0
- data/lib/karafka/pro.rb +13 -0
- data/lib/karafka/process.rb +24 -8
- data/lib/karafka/processing/coordinator.rb +181 -0
- data/lib/karafka/processing/coordinators_buffer.rb +62 -0
- data/lib/karafka/processing/executor.rb +155 -0
- data/lib/karafka/processing/executors_buffer.rb +72 -0
- data/lib/karafka/processing/expansions_selector.rb +22 -0
- data/lib/karafka/processing/inline_insights/consumer.rb +41 -0
- data/lib/karafka/processing/inline_insights/listener.rb +19 -0
- data/lib/karafka/processing/inline_insights/tracker.rb +128 -0
- data/lib/karafka/processing/jobs/base.rb +55 -0
- data/lib/karafka/processing/jobs/consume.rb +45 -0
- data/lib/karafka/processing/jobs/idle.rb +24 -0
- data/lib/karafka/processing/jobs/revoked.rb +22 -0
- data/lib/karafka/processing/jobs/shutdown.rb +23 -0
- data/lib/karafka/processing/jobs_builder.rb +28 -0
- data/lib/karafka/processing/jobs_queue.rb +150 -0
- data/lib/karafka/processing/partitioner.rb +24 -0
- data/lib/karafka/processing/result.rb +42 -0
- data/lib/karafka/processing/scheduler.rb +22 -0
- data/lib/karafka/processing/strategies/aj_dlq_mom.rb +44 -0
- data/lib/karafka/processing/strategies/aj_mom.rb +21 -0
- data/lib/karafka/processing/strategies/base.rb +52 -0
- data/lib/karafka/processing/strategies/default.rb +158 -0
- data/lib/karafka/processing/strategies/dlq.rb +88 -0
- data/lib/karafka/processing/strategies/dlq_mom.rb +49 -0
- data/lib/karafka/processing/strategies/mom.rb +29 -0
- data/lib/karafka/processing/strategy_selector.rb +47 -0
- data/lib/karafka/processing/worker.rb +93 -0
- data/lib/karafka/processing/workers_batch.rb +27 -0
- data/lib/karafka/railtie.rb +141 -0
- data/lib/karafka/routing/activity_manager.rb +84 -0
- data/lib/karafka/routing/builder.rb +45 -19
- data/lib/karafka/routing/consumer_group.rb +56 -20
- data/lib/karafka/routing/consumer_mapper.rb +1 -12
- data/lib/karafka/routing/features/active_job/builder.rb +33 -0
- data/lib/karafka/routing/features/active_job/config.rb +15 -0
- data/lib/karafka/routing/features/active_job/contracts/topic.rb +44 -0
- data/lib/karafka/routing/features/active_job/proxy.rb +14 -0
- data/lib/karafka/routing/features/active_job/topic.rb +33 -0
- data/lib/karafka/routing/features/active_job.rb +13 -0
- data/lib/karafka/routing/features/base/expander.rb +59 -0
- data/lib/karafka/routing/features/base.rb +71 -0
- data/lib/karafka/routing/features/dead_letter_queue/config.rb +19 -0
- data/lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb +46 -0
- data/lib/karafka/routing/features/dead_letter_queue/topic.rb +41 -0
- data/lib/karafka/routing/features/dead_letter_queue.rb +16 -0
- data/lib/karafka/routing/features/declaratives/config.rb +18 -0
- data/lib/karafka/routing/features/declaratives/contracts/topic.rb +33 -0
- data/lib/karafka/routing/features/declaratives/topic.rb +44 -0
- data/lib/karafka/routing/features/declaratives.rb +14 -0
- data/lib/karafka/routing/features/inline_insights/config.rb +15 -0
- data/lib/karafka/routing/features/inline_insights/contracts/topic.rb +27 -0
- data/lib/karafka/routing/features/inline_insights/topic.rb +31 -0
- data/lib/karafka/routing/features/inline_insights.rb +40 -0
- data/lib/karafka/routing/features/manual_offset_management/config.rb +15 -0
- data/lib/karafka/routing/features/manual_offset_management/contracts/topic.rb +27 -0
- data/lib/karafka/routing/features/manual_offset_management/topic.rb +35 -0
- data/lib/karafka/routing/features/manual_offset_management.rb +18 -0
- data/lib/karafka/routing/proxy.rb +22 -21
- data/lib/karafka/routing/router.rb +24 -10
- data/lib/karafka/routing/subscription_group.rb +110 -0
- data/lib/karafka/routing/subscription_groups_builder.rb +65 -0
- data/lib/karafka/routing/topic.rb +87 -24
- data/lib/karafka/routing/topics.rb +46 -0
- data/lib/karafka/runner.rb +52 -0
- data/lib/karafka/serialization/json/deserializer.rb +7 -15
- data/lib/karafka/server.rb +113 -37
- data/lib/karafka/setup/attributes_map.rb +348 -0
- data/lib/karafka/setup/config.rb +256 -175
- data/lib/karafka/status.rb +54 -7
- data/lib/karafka/templates/example_consumer.rb.erb +16 -0
- data/lib/karafka/templates/karafka.rb.erb +33 -55
- data/lib/karafka/time_trackers/base.rb +14 -0
- data/lib/karafka/time_trackers/pause.rb +122 -0
- data/lib/karafka/time_trackers/poll.rb +69 -0
- data/lib/karafka/version.rb +1 -1
- data/lib/karafka.rb +91 -17
- data/renovate.json +9 -0
- data.tar.gz.sig +0 -0
- metadata +330 -168
- metadata.gz.sig +0 -0
- data/MIT-LICENCE +0 -18
- data/certs/mensfeld.pem +0 -25
- data/config/errors.yml +0 -41
- data/lib/karafka/assignment_strategies/round_robin.rb +0 -13
- data/lib/karafka/attributes_map.rb +0 -63
- data/lib/karafka/backends/inline.rb +0 -16
- data/lib/karafka/base_responder.rb +0 -226
- data/lib/karafka/cli/flow.rb +0 -48
- data/lib/karafka/cli/missingno.rb +0 -19
- data/lib/karafka/code_reloader.rb +0 -67
- data/lib/karafka/connection/api_adapter.rb +0 -158
- data/lib/karafka/connection/batch_delegator.rb +0 -55
- data/lib/karafka/connection/builder.rb +0 -23
- data/lib/karafka/connection/message_delegator.rb +0 -36
- data/lib/karafka/consumers/batch_metadata.rb +0 -10
- data/lib/karafka/consumers/callbacks.rb +0 -71
- data/lib/karafka/consumers/includer.rb +0 -64
- data/lib/karafka/consumers/responders.rb +0 -24
- data/lib/karafka/consumers/single_params.rb +0 -15
- data/lib/karafka/contracts/consumer_group_topic.rb +0 -19
- data/lib/karafka/contracts/responder_usage.rb +0 -54
- data/lib/karafka/fetcher.rb +0 -42
- data/lib/karafka/helpers/class_matcher.rb +0 -88
- data/lib/karafka/helpers/config_retriever.rb +0 -46
- data/lib/karafka/helpers/inflector.rb +0 -26
- data/lib/karafka/instrumentation/stdout_listener.rb +0 -140
- data/lib/karafka/params/batch_metadata.rb +0 -26
- data/lib/karafka/params/builders/batch_metadata.rb +0 -30
- data/lib/karafka/params/builders/params.rb +0 -38
- data/lib/karafka/params/builders/params_batch.rb +0 -25
- data/lib/karafka/params/params_batch.rb +0 -60
- data/lib/karafka/patches/ruby_kafka.rb +0 -47
- data/lib/karafka/persistence/client.rb +0 -29
- data/lib/karafka/persistence/consumers.rb +0 -45
- data/lib/karafka/persistence/topics.rb +0 -48
- data/lib/karafka/responders/builder.rb +0 -36
- data/lib/karafka/responders/topic.rb +0 -55
- data/lib/karafka/routing/topic_mapper.rb +0 -53
- data/lib/karafka/serialization/json/serializer.rb +0 -31
- data/lib/karafka/setup/configurators/water_drop.rb +0 -36
- 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
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
]
|
18
|
-
|
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
|
-
|
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
|
-
#
|
24
|
-
|
25
|
-
# @
|
26
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
38
|
-
|
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
|
-
#
|
44
|
-
#
|
45
|
-
|
46
|
-
|
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
|
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
|
data/lib/karafka/cli/base.rb
CHANGED
@@ -1,31 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Karafka
|
4
|
-
class Cli
|
4
|
+
class Cli
|
5
5
|
# Base class for all the command that we want to define
|
6
|
-
# This base class provides
|
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
|
-
|
8
|
+
# @return [Hash] given command cli options
|
9
|
+
attr_reader :options
|
22
10
|
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
47
|
-
def desc(
|
48
|
-
@desc ||=
|
52
|
+
# @param desc [String] Description of a given cli command
|
53
|
+
def desc(desc = nil)
|
54
|
+
@desc ||= desc
|
49
55
|
end
|
50
56
|
|
51
|
-
#
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
64
|
+
# Parses the CLI options
|
65
|
+
# @return [Hash] hash with parsed values
|
66
|
+
def parse_options
|
67
|
+
options = {}
|
58
68
|
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
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
|
data/lib/karafka/cli/console.rb
CHANGED
@@ -2,29 +2,35 @@
|
|
2
2
|
|
3
3
|
module Karafka
|
4
4
|
# Karafka framework Cli
|
5
|
-
class Cli
|
5
|
+
class Cli
|
6
6
|
# Console Karafka Cli action
|
7
7
|
class Console < Base
|
8
|
-
desc '
|
9
|
-
|
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
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
27
|
-
|
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
|
data/lib/karafka/cli/info.rb
CHANGED
@@ -2,29 +2,64 @@
|
|
2
2
|
|
3
3
|
module Karafka
|
4
4
|
# Karafka framework Cli
|
5
|
-
class Cli
|
5
|
+
class Cli
|
6
6
|
# Info Karafka Cli action
|
7
7
|
class Info < Base
|
8
|
-
desc '
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
"
|
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.
|
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
|
data/lib/karafka/cli/install.rb
CHANGED
@@ -4,37 +4,37 @@ require 'erb'
|
|
4
4
|
|
5
5
|
module Karafka
|
6
6
|
# Karafka framework Cli
|
7
|
-
class Cli
|
7
|
+
class Cli
|
8
8
|
# Install Karafka Cli action
|
9
9
|
class Install < Base
|
10
|
-
|
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
|
-
|
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
|
-
'
|
26
|
+
'example_consumer.rb.erb' => 'app/consumers/example_consumer.rb'
|
28
27
|
}.freeze
|
29
28
|
|
30
|
-
|
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
|
-
|
53
|
+
pathed_target = Karafka.root.join(target)
|
49
54
|
|
50
55
|
template = File.read(Karafka.core_root.join("templates/#{source}"))
|
51
|
-
|
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(
|
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
|