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
@@ -1,26 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
<% unless rails? -%>
|
2
3
|
|
3
|
-
<% if rails? -%>
|
4
|
-
ENV['RAILS_ENV'] ||= 'development'
|
5
|
-
ENV['KARAFKA_ENV'] = ENV['RAILS_ENV']
|
6
|
-
require ::File.expand_path('../config/environment', __FILE__)
|
7
|
-
Rails.application.eager_load!
|
8
|
-
|
9
|
-
# This lines will make Karafka print to stdout like puma or unicorn
|
10
|
-
if Rails.env.development?
|
11
|
-
Rails.logger.extend(
|
12
|
-
ActiveSupport::Logger.broadcast(
|
13
|
-
ActiveSupport::Logger.new($stdout)
|
14
|
-
)
|
15
|
-
)
|
16
|
-
end
|
17
|
-
<% else -%>
|
18
4
|
# This file is auto-generated during the install process.
|
19
5
|
# If by any chance you've wanted a setup for Rails app, either run the `karafka:install`
|
20
6
|
# command again or refer to the install templates available in the source codes
|
21
7
|
|
22
|
-
ENV['
|
23
|
-
ENV['KARAFKA_ENV'] ||= ENV['RACK_ENV']
|
8
|
+
ENV['KARAFKA_ENV'] ||= 'development'
|
24
9
|
Bundler.require(:default, ENV['KARAFKA_ENV'])
|
25
10
|
|
26
11
|
# Zeitwerk custom loader for loading the app components before the whole
|
@@ -31,9 +16,7 @@ APP_LOADER.enable_reloading
|
|
31
16
|
%w[
|
32
17
|
lib
|
33
18
|
app/consumers
|
34
|
-
|
35
|
-
app/workers
|
36
|
-
].each(&APP_LOADER.method(:push_dir))
|
19
|
+
].each { |dir| APP_LOADER.push_dir(dir) }
|
37
20
|
|
38
21
|
APP_LOADER.setup
|
39
22
|
APP_LOADER.eager_load
|
@@ -41,10 +24,12 @@ APP_LOADER.eager_load
|
|
41
24
|
|
42
25
|
class KarafkaApp < Karafka::App
|
43
26
|
setup do |config|
|
44
|
-
config.kafka
|
27
|
+
config.kafka = { 'bootstrap.servers': '127.0.0.1:9092' }
|
45
28
|
config.client_id = 'example_app'
|
46
29
|
<% if rails? -%>
|
47
|
-
|
30
|
+
# Recreate consumers with each batch. This will allow Rails code reload to work in the
|
31
|
+
# development mode. Otherwise Karafka process would not be aware of code changes
|
32
|
+
config.consumer_persistence = !Rails.env.development?
|
48
33
|
<% end -%>
|
49
34
|
end
|
50
35
|
|
@@ -52,41 +37,34 @@ class KarafkaApp < Karafka::App
|
|
52
37
|
# interested in logging events for certain environments. Since instrumentation
|
53
38
|
# notifications add extra boilerplate, if you want to achieve max performance,
|
54
39
|
# listen to only what you really need for given environment.
|
55
|
-
Karafka.monitor.subscribe(
|
56
|
-
Karafka.monitor.subscribe(Karafka::Instrumentation::StdoutListener.new)
|
40
|
+
Karafka.monitor.subscribe(Karafka::Instrumentation::LoggerListener.new)
|
57
41
|
# Karafka.monitor.subscribe(Karafka::Instrumentation::ProctitleListener.new)
|
58
42
|
|
59
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
consumer_groups.draw do
|
71
|
-
# topic :example do
|
72
|
-
# consumer ExampleConsumer
|
73
|
-
# end
|
43
|
+
# This logger prints the producer development info using the Karafka logger.
|
44
|
+
# It is similar to the consumer logger listener but producer oriented.
|
45
|
+
Karafka.producer.monitor.subscribe(
|
46
|
+
WaterDrop::Instrumentation::LoggerListener.new(
|
47
|
+
# Log producer operations using the Karafka logger
|
48
|
+
Karafka.logger,
|
49
|
+
# If you set this to true, logs will contain each message details
|
50
|
+
# Please note, that this can be extensive
|
51
|
+
log_messages: false
|
52
|
+
)
|
53
|
+
)
|
74
54
|
|
75
|
-
|
76
|
-
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
55
|
+
routes.draw do
|
56
|
+
<% if rails? -%>
|
57
|
+
# Uncomment this if you use Karafka with ActiveJob
|
58
|
+
# You need to define the topic per each queue name you use
|
59
|
+
# active_job_topic :default
|
60
|
+
<% end -%>
|
61
|
+
topic :example do
|
62
|
+
# Uncomment this if you want Karafka to manage your topics configuration
|
63
|
+
# Managing topics configuration via routing will allow you to ensure config consistency
|
64
|
+
# across multiple environments
|
65
|
+
#
|
66
|
+
# config(partitions: 2, 'cleanup.policy': 'compact')
|
67
|
+
consumer ExampleConsumer
|
68
|
+
end
|
84
69
|
end
|
85
70
|
end
|
86
|
-
|
87
|
-
Karafka.monitor.subscribe('app.initialized') do
|
88
|
-
# Put here all the things you want to do after the Karafka framework
|
89
|
-
# initialization
|
90
|
-
end
|
91
|
-
|
92
|
-
KarafkaApp.boot!
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
# Time trackers module.
|
5
|
+
#
|
6
|
+
# Time trackers are used to track time in context of having a time poll (amount of time
|
7
|
+
# available for processing) or a pausing engine (pause for a time period).
|
8
|
+
module TimeTrackers
|
9
|
+
# Base class for all the time-trackers.
|
10
|
+
class Base
|
11
|
+
include ::Karafka::Core::Helpers::Time
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module TimeTrackers
|
5
|
+
# Handles Kafka topic partition pausing and resuming with exponential back-offs.
|
6
|
+
# Since expiring and pausing can happen from both consumer and listener, this needs to be
|
7
|
+
# thread-safe.
|
8
|
+
#
|
9
|
+
# @note We do not have to worry about performance implications of a mutex wrapping most of the
|
10
|
+
# code here, as this is not a frequently used tracker. It is active only once per batch in
|
11
|
+
# case of long-running-jobs and upon errors.
|
12
|
+
class Pause < Base
|
13
|
+
attr_reader :attempt, :current_timeout
|
14
|
+
|
15
|
+
# @param timeout [Integer] how long should we wait when anything went wrong (in ms)
|
16
|
+
# @param max_timeout [Integer, nil] if exponential is on, what is the max value we can reach
|
17
|
+
# exponentially on which we will stay
|
18
|
+
# @param exponential_backoff [Boolean] should we wait exponentially or with the same
|
19
|
+
# timeout value
|
20
|
+
# @return [Karafka::TimeTrackers::Pause]
|
21
|
+
# @example
|
22
|
+
# options = { timeout: 1000, max_timeout: 1000, exponential_backoff: false }
|
23
|
+
# pause = Karafka::TimeTrackers::Pause.new(**options)
|
24
|
+
# pause.expired? #=> true
|
25
|
+
# pause.paused? #=> false
|
26
|
+
# pause.pause
|
27
|
+
# pause.increment
|
28
|
+
# sleep(1.1)
|
29
|
+
# pause.paused? #=> true
|
30
|
+
# pause.expired? #=> true
|
31
|
+
# pause.attempt #=> 1
|
32
|
+
# pause.pause
|
33
|
+
# pause.increment
|
34
|
+
# pause.attempt #=> 2
|
35
|
+
# pause.paused? #=> true
|
36
|
+
# pause.expired? #=> false
|
37
|
+
# pause.resume
|
38
|
+
# pause.attempt #=> 2
|
39
|
+
# pause.paused? #=> false
|
40
|
+
# pause.reset
|
41
|
+
# pause.attempt #=> 0
|
42
|
+
def initialize(timeout:, max_timeout:, exponential_backoff:)
|
43
|
+
@started_at = nil
|
44
|
+
@attempt = 0
|
45
|
+
@timeout = timeout
|
46
|
+
@current_timeout = timeout
|
47
|
+
@max_timeout = max_timeout
|
48
|
+
@exponential_backoff = exponential_backoff
|
49
|
+
@mutex = Mutex.new
|
50
|
+
super()
|
51
|
+
end
|
52
|
+
|
53
|
+
# Pauses the processing from now till the end of the interval (backoff or non-backoff)
|
54
|
+
# and records the attempt.
|
55
|
+
# @param timeout [Integer] timeout value in milliseconds that overwrites the default timeout
|
56
|
+
# @note Providing this value can be useful when we explicitly want to pause for a certain
|
57
|
+
# period of time, outside of any regular pausing logic
|
58
|
+
def pause(timeout = backoff_interval)
|
59
|
+
@mutex.synchronize do
|
60
|
+
@current_timeout = timeout
|
61
|
+
@started_at = monotonic_now
|
62
|
+
@ends_at = @started_at + timeout
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Increments the number of attempt by 1
|
67
|
+
def increment
|
68
|
+
@mutex.synchronize do
|
69
|
+
@attempt += 1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Marks the pause as resumed.
|
74
|
+
def resume
|
75
|
+
@mutex.synchronize do
|
76
|
+
@started_at = nil
|
77
|
+
@ends_at = nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Expires the pause, so it can be considered expired
|
82
|
+
def expire
|
83
|
+
@mutex.synchronize do
|
84
|
+
@ends_at = nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [Boolean] are we paused from processing
|
89
|
+
def paused?
|
90
|
+
@mutex.synchronize do
|
91
|
+
!@started_at.nil?
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [Boolean] did the pause expire
|
96
|
+
def expired?
|
97
|
+
@mutex.synchronize do
|
98
|
+
@ends_at ? monotonic_now >= @ends_at : true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Resets the pause attempt count.
|
103
|
+
def reset
|
104
|
+
@mutex.synchronize do
|
105
|
+
@attempt = 0
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
# Computers the exponential backoff
|
112
|
+
# @return [Integer] backoff in milliseconds
|
113
|
+
def backoff_interval
|
114
|
+
backoff_factor = @exponential_backoff ? 2**@attempt : 1
|
115
|
+
|
116
|
+
timeout = backoff_factor * @timeout
|
117
|
+
|
118
|
+
@max_timeout && timeout > @max_timeout ? @max_timeout : timeout
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module TimeTrackers
|
5
|
+
# Object used to keep track of time we've used running certain operations. Polling is
|
6
|
+
# running in a single thread, thus we do not have to worry about this being thread-safe.
|
7
|
+
#
|
8
|
+
# @example Keep track of sleeping and stop after 3 seconds of 0.1 sleep intervals
|
9
|
+
# time_poll = Poll.new(3000)
|
10
|
+
# time_poll.start
|
11
|
+
#
|
12
|
+
# until time_poll.exceeded?
|
13
|
+
# time_poll.start
|
14
|
+
# puts "I have #{time_poll.remaining.to_i}ms remaining to sleep..."
|
15
|
+
# sleep(0.1)
|
16
|
+
# time_poll.checkpoint
|
17
|
+
# end
|
18
|
+
class Poll < Base
|
19
|
+
attr_reader :remaining, :attempts
|
20
|
+
|
21
|
+
# @param total_time [Integer] amount of milliseconds before we exceed the given time limit
|
22
|
+
# @return [TimeTracker] time poll instance
|
23
|
+
def initialize(total_time)
|
24
|
+
@remaining = total_time
|
25
|
+
@attempts = 0
|
26
|
+
super()
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean] did we exceed the time limit
|
30
|
+
def exceeded?
|
31
|
+
@remaining <= 0
|
32
|
+
end
|
33
|
+
|
34
|
+
# Starts time tracking.
|
35
|
+
def start
|
36
|
+
@attempts += 1
|
37
|
+
@started_at = monotonic_now
|
38
|
+
end
|
39
|
+
|
40
|
+
# Stops time tracking of a given piece of code and updates the remaining time.
|
41
|
+
def checkpoint
|
42
|
+
@remaining -= (monotonic_now - @started_at)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Boolean] If anything went wrong, can we retry after a backoff period or not
|
46
|
+
# (do we have enough time)
|
47
|
+
def retryable?
|
48
|
+
remaining > backoff_interval
|
49
|
+
end
|
50
|
+
|
51
|
+
# Sleeps for amount of time matching attempt, so we sleep more with each attempt in case of
|
52
|
+
# a retry.
|
53
|
+
def backoff
|
54
|
+
# backoff should not be included in the remaining time computation, otherwise it runs
|
55
|
+
# shortly, never back-offing beyond a small number because of the sleep
|
56
|
+
@remaining += backoff_interval
|
57
|
+
# Sleep requires seconds not ms
|
58
|
+
sleep(backoff_interval / 1_000.0)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# @return [Integer] milliseconds of the backoff time
|
64
|
+
def backoff_interval
|
65
|
+
100 * attempts
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/karafka/version.rb
CHANGED
data/lib/karafka.rb
CHANGED
@@ -1,34 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
%w[
|
4
|
+
karafka-core
|
4
5
|
delegate
|
5
6
|
English
|
7
|
+
rdkafka
|
6
8
|
waterdrop
|
7
|
-
kafka
|
8
|
-
envlogic
|
9
9
|
json
|
10
|
-
thor
|
11
10
|
forwardable
|
12
11
|
fileutils
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
openssl
|
13
|
+
optparse
|
14
|
+
base64
|
15
|
+
date
|
16
|
+
singleton
|
17
|
+
digest
|
19
18
|
zeitwerk
|
19
|
+
concurrent/atomic/atomic_fixnum
|
20
20
|
].each(&method(:require))
|
21
21
|
|
22
|
-
# Karafka
|
22
|
+
# Karafka framework main namespace
|
23
23
|
module Karafka
|
24
|
-
extend Envlogic
|
25
|
-
|
26
24
|
class << self
|
25
|
+
# @return [Karafka::Env] env instance that allows us to check environment
|
26
|
+
def env
|
27
|
+
@env ||= Env.new
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param environment [String, Symbol] new environment that we want to set
|
31
|
+
# @return [Karafka::Env] env instance
|
32
|
+
# @example Assign new environment to Karafka::App
|
33
|
+
# Karafka::App.env = :production
|
34
|
+
def env=(environment)
|
35
|
+
env.replace(environment.to_s)
|
36
|
+
end
|
37
|
+
|
27
38
|
# @return [Logger] logger that we want to use. Will use ::Karafka::Logger by default
|
28
39
|
def logger
|
29
40
|
@logger ||= App.config.logger
|
30
41
|
end
|
31
42
|
|
43
|
+
# @return [WaterDrop::Producer] waterdrop messages producer
|
44
|
+
def producer
|
45
|
+
@producer ||= App.config.producer
|
46
|
+
end
|
47
|
+
|
32
48
|
# @return [::Karafka::Monitor] monitor that we want to use
|
33
49
|
def monitor
|
34
50
|
@monitor ||= App.config.monitor
|
@@ -49,6 +65,24 @@ module Karafka
|
|
49
65
|
Pathname.new(File.expand_path('karafka', __dir__))
|
50
66
|
end
|
51
67
|
|
68
|
+
# @return [Boolean] true if there is a valid pro token present
|
69
|
+
def pro?
|
70
|
+
App.config.license.token != false
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [Boolean] Do we run within/with Rails. We use this to initialize Railtie and proxy
|
74
|
+
# the console invocation to Rails
|
75
|
+
def rails?
|
76
|
+
return @rails if instance_variable_defined?('@rails')
|
77
|
+
|
78
|
+
# Do not load Rails again if already loaded
|
79
|
+
Object.const_defined?('Rails::Railtie') || require('rails')
|
80
|
+
|
81
|
+
@rails = true
|
82
|
+
rescue LoadError
|
83
|
+
@rails = false
|
84
|
+
end
|
85
|
+
|
52
86
|
# @return [String] path to a default file that contains booting procedure etc
|
53
87
|
# @note By default it is a file called 'karafka.rb' but it can be specified as you wish if you
|
54
88
|
# have Karafka that is merged into a Sinatra/Rails app and karafka.rb is taken.
|
@@ -61,12 +95,52 @@ module Karafka
|
|
61
95
|
def boot_file
|
62
96
|
Pathname.new(ENV['KARAFKA_BOOT_FILE'] || File.join(Karafka.root, 'karafka.rb'))
|
63
97
|
end
|
98
|
+
|
99
|
+
# We need to be able to overwrite both monitor and logger after the configuration in case they
|
100
|
+
# would be changed because those two (with defaults) can be used prior to the setup and their
|
101
|
+
# state change should be reflected in the updated setup
|
102
|
+
#
|
103
|
+
# This method refreshes the things that might have been altered by the configuration
|
104
|
+
def refresh!
|
105
|
+
config = ::Karafka::App.config
|
106
|
+
|
107
|
+
@logger = config.logger
|
108
|
+
@producer = config.producer
|
109
|
+
@monitor = config.monitor
|
110
|
+
end
|
64
111
|
end
|
65
112
|
end
|
66
113
|
|
67
|
-
Zeitwerk::Loader
|
68
|
-
|
69
|
-
|
70
|
-
|
114
|
+
loader = Zeitwerk::Loader.for_gem
|
115
|
+
# Do not load Rails extensions by default, this will be handled by Railtie if they are needed
|
116
|
+
loader.ignore(Karafka.gem_root.join('lib/active_job'))
|
117
|
+
# Do not load CurrentAttributes components as they will be loaded if needed
|
118
|
+
# @note We have to exclude both the .rb file as well as the whole directory so users can require
|
119
|
+
# current attributes only when needed
|
120
|
+
loader.ignore(Karafka.gem_root.join('lib/karafka/active_job/current_attributes'))
|
121
|
+
loader.ignore(Karafka.gem_root.join('lib/karafka/active_job/current_attributes.rb'))
|
122
|
+
# Do not load Railtie. It will load if after everything is ready, so we don't have to load any
|
123
|
+
# Karafka components when we require this railtie. Railtie needs to be loaded last.
|
124
|
+
loader.ignore(Karafka.gem_root.join('lib/karafka/railtie'))
|
125
|
+
# Do not load pro components as they will be loaded if needed and allowed
|
126
|
+
loader.ignore(Karafka.core_root.join('pro/'))
|
127
|
+
# Do not load vendors instrumentation components. Those need to be required manually if needed
|
128
|
+
loader.ignore(Karafka.core_root.join('instrumentation/vendors'))
|
129
|
+
loader.setup
|
130
|
+
loader.eager_load
|
131
|
+
|
132
|
+
# This will load features but since Pro are not loaded automatically, they will not be visible
|
133
|
+
# nor included here
|
134
|
+
::Karafka::Routing::Features::Base.load_all
|
135
|
+
|
136
|
+
# We need to detect and require (not setup) Pro components during the gem load, because we need
|
137
|
+
# to make pro components available in case anyone wants to use them as a base to their own
|
138
|
+
# custom components. Otherwise inheritance would not work.
|
139
|
+
Karafka::Licenser.detect do
|
140
|
+
require 'karafka/pro/loader'
|
141
|
+
|
142
|
+
Karafka::Pro::Loader.require_all
|
143
|
+
end
|
71
144
|
|
72
|
-
|
145
|
+
# Load railtie after everything else is ready so we know we can rely on it.
|
146
|
+
require 'karafka/railtie'
|
data/renovate.json
ADDED
data.tar.gz.sig
CHANGED
Binary file
|