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
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
# Class responsible for deciding what type of job should we build to run a given command and
|
6
|
+
# for building a proper job for it.
|
7
|
+
class JobsBuilder
|
8
|
+
# @param executor [Karafka::Processing::Executor]
|
9
|
+
# @param messages [Karafka::Messages::Messages] messages batch to be consumed
|
10
|
+
# @return [Karafka::Processing::Jobs::Consume] consumption job
|
11
|
+
def consume(executor, messages)
|
12
|
+
Jobs::Consume.new(executor, messages)
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param executor [Karafka::Processing::Executor]
|
16
|
+
# @return [Karafka::Processing::Jobs::Revoked] revocation job
|
17
|
+
def revoked(executor)
|
18
|
+
Jobs::Revoked.new(executor)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param executor [Karafka::Processing::Executor]
|
22
|
+
# @return [Karafka::Processing::Jobs::Shutdown] shutdown job
|
23
|
+
def shutdown(executor)
|
24
|
+
Jobs::Shutdown.new(executor)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
# This is the key work component for Karafka jobs distribution. It provides API for running
|
6
|
+
# jobs in parallel while operating within more than one subscription group.
|
7
|
+
#
|
8
|
+
# We need to take into consideration fact, that more than one subscription group can operate
|
9
|
+
# on this queue, that's why internally we keep track of processing per group.
|
10
|
+
#
|
11
|
+
# We work with the assumption, that partitions data is evenly distributed.
|
12
|
+
class JobsQueue
|
13
|
+
# @return [Karafka::Processing::JobsQueue]
|
14
|
+
def initialize
|
15
|
+
@queue = Queue.new
|
16
|
+
# Those queues will act as semaphores internally. Since we need an indicator for waiting
|
17
|
+
# we could use Thread.pass but this is expensive. Instead we can just lock until any
|
18
|
+
# of the workers finishes their work and we can re-check. This means that in the worse
|
19
|
+
# scenario, we will context switch 10 times per poll instead of getting this thread
|
20
|
+
# scheduled by Ruby hundreds of thousands of times per group.
|
21
|
+
# We cannot use a single semaphore as it could potentially block in listeners that should
|
22
|
+
# process with their data and also could unlock when a given group needs to remain locked
|
23
|
+
@semaphores = Concurrent::Map.new do |h, k|
|
24
|
+
h.compute_if_absent(k) { Queue.new }
|
25
|
+
end
|
26
|
+
|
27
|
+
@in_processing = Hash.new { |h, k| h[k] = [] }
|
28
|
+
|
29
|
+
@mutex = Mutex.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns number of jobs that are either enqueued or in processing (but not finished)
|
33
|
+
# @return [Integer] number of elements in the queue
|
34
|
+
# @note Using `#pop` won't decrease this number as only marking job as completed does this
|
35
|
+
def size
|
36
|
+
@in_processing.values.map(&:size).sum
|
37
|
+
end
|
38
|
+
|
39
|
+
# Adds the job to the internal main queue, scheduling it for execution in a worker and marks
|
40
|
+
# this job as in processing pipeline.
|
41
|
+
#
|
42
|
+
# @param job [Jobs::Base] job that we want to run
|
43
|
+
def <<(job)
|
44
|
+
# We do not push the job if the queue is closed as it means that it would anyhow not be
|
45
|
+
# executed
|
46
|
+
return if @queue.closed?
|
47
|
+
|
48
|
+
@mutex.synchronize do
|
49
|
+
group = @in_processing[job.group_id]
|
50
|
+
|
51
|
+
raise(Errors::JobsQueueSynchronizationError, job.group_id) if group.include?(job)
|
52
|
+
|
53
|
+
group << job
|
54
|
+
|
55
|
+
@queue << job
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Jobs::Base, nil] waits for a job from the main queue and returns it once available
|
60
|
+
# or returns nil if the queue has been stopped and there won't be anything more to process
|
61
|
+
# ever.
|
62
|
+
# @note This command is blocking and will wait until any job is available on the main queue
|
63
|
+
def pop
|
64
|
+
@queue.pop
|
65
|
+
end
|
66
|
+
|
67
|
+
# Causes the wait lock to re-check the lock conditions and potential unlock.
|
68
|
+
# @param group_id [String] id of the group we want to unlock for one tick
|
69
|
+
# @note This does not release the wait lock. It just causes a conditions recheck
|
70
|
+
def tick(group_id)
|
71
|
+
@semaphores[group_id] << true
|
72
|
+
end
|
73
|
+
|
74
|
+
# Marks a given job from a given group as completed. When there are no more jobs from a given
|
75
|
+
# group to be executed, we won't wait.
|
76
|
+
#
|
77
|
+
# @param [Jobs::Base] job that was completed
|
78
|
+
def complete(job)
|
79
|
+
@mutex.synchronize do
|
80
|
+
@in_processing[job.group_id].delete(job)
|
81
|
+
tick(job.group_id)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Clears the processing states for a provided group. Useful when a recovery happens and we
|
86
|
+
# need to clean up state but only for a given subscription group.
|
87
|
+
#
|
88
|
+
# @param group_id [String]
|
89
|
+
def clear(group_id)
|
90
|
+
@mutex.synchronize do
|
91
|
+
@in_processing[group_id].clear
|
92
|
+
# We unlock it just in case it was blocked when clearing started
|
93
|
+
tick(group_id)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Stops the whole processing queue.
|
98
|
+
def close
|
99
|
+
@mutex.synchronize do
|
100
|
+
return if @queue.closed?
|
101
|
+
|
102
|
+
@queue.close
|
103
|
+
@semaphores.each_value(&:close)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# @param group_id [String]
|
108
|
+
#
|
109
|
+
# @return [Boolean] tell us if we have anything in the processing (or for processing) from
|
110
|
+
# a given group.
|
111
|
+
def empty?(group_id)
|
112
|
+
@mutex.synchronize do
|
113
|
+
@in_processing[group_id].empty?
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Blocks when there are things in the queue in a given group and waits until all the blocking
|
118
|
+
# jobs from a given group are completed
|
119
|
+
#
|
120
|
+
# @param group_id [String] id of the group in which jobs we're interested.
|
121
|
+
# @note This method is blocking.
|
122
|
+
def wait(group_id)
|
123
|
+
# Go doing other things while we cannot process and wait for anyone to finish their work
|
124
|
+
# and re-check the wait status
|
125
|
+
@semaphores[group_id].pop while wait?(group_id)
|
126
|
+
end
|
127
|
+
|
128
|
+
# - `busy` - number of jobs that are currently being processed (active work)
|
129
|
+
# - `enqueued` - number of jobs in the queue that are waiting to be picked up by a worker
|
130
|
+
#
|
131
|
+
# @return [Hash] hash with basic usage statistics of this queue.
|
132
|
+
def statistics
|
133
|
+
{
|
134
|
+
busy: size - @queue.size,
|
135
|
+
enqueued: @queue.size
|
136
|
+
}.freeze
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
# @param group_id [String] id of the group in which jobs we're interested.
|
142
|
+
# @return [Boolean] should we keep waiting or not
|
143
|
+
# @note We do not wait for non-blocking jobs. Their flow should allow for `poll` running
|
144
|
+
# as they may exceed `max.poll.interval`
|
145
|
+
def wait?(group_id)
|
146
|
+
!@in_processing[group_id].all?(&:non_blocking?)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
# Basic partitioner for work division
|
6
|
+
# It does not divide any work.
|
7
|
+
class Partitioner
|
8
|
+
# @param subscription_group [Karafka::Routing::SubscriptionGroup] subscription group
|
9
|
+
def initialize(subscription_group)
|
10
|
+
@subscription_group = subscription_group
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param _topic [String] topic name
|
14
|
+
# @param messages [Array<Karafka::Messages::Message>] karafka messages
|
15
|
+
# @param _coordinator [Karafka::Processing::Coordinator] processing coordinator that will
|
16
|
+
# be used with those messages
|
17
|
+
# @yieldparam [Integer] group id
|
18
|
+
# @yieldparam [Array<Karafka::Messages::Message>] karafka messages
|
19
|
+
def call(_topic, messages, _coordinator)
|
20
|
+
yield(0, messages)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
# A simple object that allows us to keep track of processing state.
|
6
|
+
# It allows to indicate if given thing moved from success to a failure or the other way around
|
7
|
+
# Useful for tracking consumption state
|
8
|
+
class Result
|
9
|
+
attr_reader :cause
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@success = true
|
13
|
+
@cause = false
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Boolean]
|
17
|
+
def success?
|
18
|
+
@success
|
19
|
+
end
|
20
|
+
|
21
|
+
# Marks state as successful
|
22
|
+
def success!
|
23
|
+
@success = true
|
24
|
+
# We set cause to false so the previous error that occurred does not leak when error is
|
25
|
+
# no longer present
|
26
|
+
@cause = false
|
27
|
+
end
|
28
|
+
|
29
|
+
# Marks state as failure
|
30
|
+
# @param cause [StandardError] error that occurred and caused failure
|
31
|
+
def failure!(cause)
|
32
|
+
@success = false
|
33
|
+
@cause = cause
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Boolean] true if processing failed
|
37
|
+
def failure?
|
38
|
+
!@success
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
# FIFO scheduler for messages coming from various topics and partitions
|
6
|
+
class Scheduler
|
7
|
+
# Schedules jobs in the fifo order
|
8
|
+
#
|
9
|
+
# @param queue [Karafka::Processing::JobsQueue] queue where we want to put the jobs
|
10
|
+
# @param jobs_array [Array<Karafka::Processing::Jobs::Base>] jobs we want to schedule
|
11
|
+
def schedule_consumption(queue, jobs_array)
|
12
|
+
jobs_array.each do |job|
|
13
|
+
queue << job
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Both revocation and shutdown jobs can also run in fifo by default
|
18
|
+
alias schedule_revocation schedule_consumption
|
19
|
+
alias schedule_shutdown schedule_consumption
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
module Strategies
|
6
|
+
# ActiveJob strategy to cooperate with the DLQ.
|
7
|
+
#
|
8
|
+
# While AJ is uses MOM by default because it delegates the offset management to the AJ
|
9
|
+
# consumer. With DLQ however there is an extra case for skipping broken jobs with offset
|
10
|
+
# marking due to ordered processing.
|
11
|
+
module AjDlqMom
|
12
|
+
include DlqMom
|
13
|
+
|
14
|
+
# Apply strategy when only when using AJ with MOM and DLQ
|
15
|
+
FEATURES = %i[
|
16
|
+
active_job
|
17
|
+
dead_letter_queue
|
18
|
+
manual_offset_management
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
# How should we post-finalize consumption.
|
22
|
+
def handle_after_consume
|
23
|
+
return if revoked?
|
24
|
+
|
25
|
+
if coordinator.success?
|
26
|
+
# Do NOT commit offsets, they are comitted after each job in the AJ consumer.
|
27
|
+
coordinator.pause_tracker.reset
|
28
|
+
elsif coordinator.pause_tracker.attempt <= topic.dead_letter_queue.max_retries
|
29
|
+
retry_after_pause
|
30
|
+
else
|
31
|
+
coordinator.pause_tracker.reset
|
32
|
+
skippable_message, = find_skippable_message
|
33
|
+
dispatch_to_dlq(skippable_message)
|
34
|
+
# We can commit the offset here because we know that we skip it "forever" and
|
35
|
+
# since AJ consumer commits the offset after each job, we also know that the
|
36
|
+
# previous job was successful
|
37
|
+
mark_as_consumed(skippable_message)
|
38
|
+
pause(coordinator.seek_offset, nil, false)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
module Strategies
|
6
|
+
# ActiveJob enabled
|
7
|
+
# Manual offset management enabled
|
8
|
+
#
|
9
|
+
# This is the default AJ strategy since AJ cannot be used without MOM
|
10
|
+
module AjMom
|
11
|
+
include Mom
|
12
|
+
|
13
|
+
# Apply strategy when only when using AJ with MOM
|
14
|
+
FEATURES = %i[
|
15
|
+
active_job
|
16
|
+
manual_offset_management
|
17
|
+
].freeze
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
# Our processing patterns differ depending on various features configurations
|
6
|
+
# In this namespace we collect strategies for particular feature combinations to simplify the
|
7
|
+
# design. Based on features combinations we can then select handling strategy for a given case.
|
8
|
+
#
|
9
|
+
# @note The lack of common code here is intentional. It would get complex if there would be
|
10
|
+
# any type of composition, so each strategy is expected to be self-sufficient
|
11
|
+
module Strategies
|
12
|
+
# Base strategy that should be included in each strategy, just to ensure the API
|
13
|
+
module Base
|
14
|
+
# What should happen before jobs are enqueued
|
15
|
+
# @note This runs from the listener thread, not recommended to put anything slow here
|
16
|
+
def handle_before_enqueue
|
17
|
+
raise NotImplementedError, 'Implement in a subclass'
|
18
|
+
end
|
19
|
+
|
20
|
+
# What should happen before we kick in the processing
|
21
|
+
def handle_before_consume
|
22
|
+
raise NotImplementedError, 'Implement in a subclass'
|
23
|
+
end
|
24
|
+
|
25
|
+
# What should happen in the processing
|
26
|
+
def handle_consume
|
27
|
+
raise NotImplementedError, 'Implement in a subclass'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Post-consumption handling
|
31
|
+
def handle_after_consume
|
32
|
+
raise NotImplementedError, 'Implement in a subclass'
|
33
|
+
end
|
34
|
+
|
35
|
+
# Idle run handling
|
36
|
+
def handle_idle
|
37
|
+
raise NotImplementedError, 'Implement in a subclass'
|
38
|
+
end
|
39
|
+
|
40
|
+
# Revocation handling
|
41
|
+
def handle_revoked
|
42
|
+
raise NotImplementedError, 'Implement in a subclass'
|
43
|
+
end
|
44
|
+
|
45
|
+
# Shutdown handling
|
46
|
+
def handle_shutdown
|
47
|
+
raise NotImplementedError, 'Implement in a subclass'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
module Strategies
|
6
|
+
# No features enabled.
|
7
|
+
# No manual offset management
|
8
|
+
# No long running jobs
|
9
|
+
# Nothing. Just standard, automatic flow
|
10
|
+
module Default
|
11
|
+
include Base
|
12
|
+
|
13
|
+
# Apply strategy for a non-feature based flow
|
14
|
+
FEATURES = %i[].freeze
|
15
|
+
|
16
|
+
# Marks message as consumed in an async way.
|
17
|
+
#
|
18
|
+
# @param message [Messages::Message] last successfully processed message.
|
19
|
+
# @return [Boolean] true if we were able to mark the offset, false otherwise.
|
20
|
+
# False indicates that we were not able and that we have lost the partition.
|
21
|
+
#
|
22
|
+
# @note We keep track of this offset in case we would mark as consumed and got error when
|
23
|
+
# processing another message. In case like this we do not pause on the message we've
|
24
|
+
# already processed but rather at the next one. This applies to both sync and async
|
25
|
+
# versions of this method.
|
26
|
+
def mark_as_consumed(message)
|
27
|
+
# Ignore earlier offsets than the one we already committed
|
28
|
+
return true if coordinator.seek_offset > message.offset
|
29
|
+
return false if revoked?
|
30
|
+
return revoked? unless client.mark_as_consumed(message)
|
31
|
+
|
32
|
+
coordinator.seek_offset = message.offset + 1
|
33
|
+
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
# Marks message as consumed in a sync way.
|
38
|
+
#
|
39
|
+
# @param message [Messages::Message] last successfully processed message.
|
40
|
+
# @return [Boolean] true if we were able to mark the offset, false otherwise.
|
41
|
+
# False indicates that we were not able and that we have lost the partition.
|
42
|
+
def mark_as_consumed!(message)
|
43
|
+
# Ignore earlier offsets than the one we already committed
|
44
|
+
return true if coordinator.seek_offset > message.offset
|
45
|
+
return false if revoked?
|
46
|
+
|
47
|
+
return revoked? unless client.mark_as_consumed!(message)
|
48
|
+
|
49
|
+
coordinator.seek_offset = message.offset + 1
|
50
|
+
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
# Triggers an async offset commit
|
55
|
+
#
|
56
|
+
# @param async [Boolean] should we use async (default) or sync commit
|
57
|
+
# @return [Boolean] true if we still own the partition.
|
58
|
+
# @note Due to its async nature, this may not fully represent the offset state in some
|
59
|
+
# edge cases (like for example going beyond max.poll.interval)
|
60
|
+
def commit_offsets(async: true)
|
61
|
+
# Do not commit if we already lost the assignment
|
62
|
+
return false if revoked?
|
63
|
+
return true if client.commit_offsets(async: async)
|
64
|
+
|
65
|
+
# This will once more check the librdkafka revocation status and will revoke the
|
66
|
+
# coordinator in case it was not revoked
|
67
|
+
revoked?
|
68
|
+
end
|
69
|
+
|
70
|
+
# Triggers a synchronous offsets commit to Kafka
|
71
|
+
#
|
72
|
+
# @return [Boolean] true if we still own the partition, false otherwise.
|
73
|
+
# @note This is fully synchronous, hence the result of this can be used in DB transactions
|
74
|
+
# etc as a way of making sure, that we still own the partition.
|
75
|
+
def commit_offsets!
|
76
|
+
commit_offsets(async: false)
|
77
|
+
end
|
78
|
+
|
79
|
+
# No actions needed for the standard flow here
|
80
|
+
def handle_before_enqueue
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
84
|
+
# Increment number of attempts
|
85
|
+
def handle_before_consume
|
86
|
+
coordinator.pause_tracker.increment
|
87
|
+
end
|
88
|
+
|
89
|
+
# Run the user consumption code
|
90
|
+
def handle_consume
|
91
|
+
Karafka.monitor.instrument('consumer.consume', caller: self)
|
92
|
+
Karafka.monitor.instrument('consumer.consumed', caller: self) do
|
93
|
+
consume
|
94
|
+
end
|
95
|
+
|
96
|
+
# Mark job as successful
|
97
|
+
coordinator.success!(self)
|
98
|
+
rescue StandardError => e
|
99
|
+
coordinator.failure!(self, e)
|
100
|
+
|
101
|
+
# Re-raise so reported in the consumer
|
102
|
+
raise e
|
103
|
+
ensure
|
104
|
+
# We need to decrease number of jobs that this coordinator coordinates as it has finished
|
105
|
+
coordinator.decrement
|
106
|
+
end
|
107
|
+
|
108
|
+
# Standard flow marks work as consumed and moves on if everything went ok.
|
109
|
+
# If there was a processing error, we will pause and continue from the next message
|
110
|
+
# (next that is +1 from the last one that was successfully marked as consumed)
|
111
|
+
def handle_after_consume
|
112
|
+
return if revoked?
|
113
|
+
|
114
|
+
if coordinator.success?
|
115
|
+
coordinator.pause_tracker.reset
|
116
|
+
|
117
|
+
# We should not move the offset automatically when the partition was paused
|
118
|
+
# If we would not do this upon a revocation during the pause time, a different process
|
119
|
+
# would pick not from the place where we paused but from the offset that would be
|
120
|
+
# automatically committed here
|
121
|
+
return if coordinator.manual_pause?
|
122
|
+
|
123
|
+
mark_as_consumed(messages.last)
|
124
|
+
else
|
125
|
+
retry_after_pause
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Code that should run on idle runs without messages available
|
130
|
+
def handle_idle
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
|
134
|
+
# We need to always un-pause the processing in case we have lost a given partition.
|
135
|
+
# Otherwise the underlying librdkafka would not know we may want to continue processing and
|
136
|
+
# the pause could in theory last forever
|
137
|
+
def handle_revoked
|
138
|
+
resume
|
139
|
+
|
140
|
+
coordinator.revoke
|
141
|
+
|
142
|
+
Karafka.monitor.instrument('consumer.revoke', caller: self)
|
143
|
+
Karafka.monitor.instrument('consumer.revoked', caller: self) do
|
144
|
+
revoked
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Runs the shutdown code
|
149
|
+
def handle_shutdown
|
150
|
+
Karafka.monitor.instrument('consumer.shutting_down', caller: self)
|
151
|
+
Karafka.monitor.instrument('consumer.shutdown', caller: self) do
|
152
|
+
shutdown
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
module Strategies
|
6
|
+
# When using dead letter queue, processing won't stop after defined number of retries
|
7
|
+
# upon encountering non-critical errors but the messages that error will be moved to a
|
8
|
+
# separate topic with their payload and metadata, so they can be handled differently.
|
9
|
+
module Dlq
|
10
|
+
include Default
|
11
|
+
|
12
|
+
# Apply strategy when only dead letter queue is turned on
|
13
|
+
FEATURES = %i[
|
14
|
+
dead_letter_queue
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
# When manual offset management is on, we do not mark anything as consumed automatically
|
18
|
+
# and we rely on the user to figure things out
|
19
|
+
def handle_after_consume
|
20
|
+
return if revoked?
|
21
|
+
|
22
|
+
if coordinator.success?
|
23
|
+
coordinator.pause_tracker.reset
|
24
|
+
|
25
|
+
return if coordinator.manual_pause?
|
26
|
+
|
27
|
+
mark_as_consumed(messages.last)
|
28
|
+
elsif coordinator.pause_tracker.attempt <= topic.dead_letter_queue.max_retries
|
29
|
+
retry_after_pause
|
30
|
+
# If we've reached number of retries that we could, we need to skip the first message
|
31
|
+
# that was not marked as consumed, pause and continue, while also moving this message
|
32
|
+
# to the dead topic
|
33
|
+
else
|
34
|
+
# We reset the pause to indicate we will now consider it as "ok".
|
35
|
+
coordinator.pause_tracker.reset
|
36
|
+
|
37
|
+
skippable_message, = find_skippable_message
|
38
|
+
|
39
|
+
# Send skippable message to the dql topic
|
40
|
+
dispatch_to_dlq(skippable_message)
|
41
|
+
|
42
|
+
# We mark the broken message as consumed and move on
|
43
|
+
mark_as_consumed(skippable_message)
|
44
|
+
|
45
|
+
return if revoked?
|
46
|
+
|
47
|
+
# We pause to backoff once just in case.
|
48
|
+
pause(coordinator.seek_offset, nil, false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Finds the message may want to skip (all, starting from first)
|
53
|
+
# @private
|
54
|
+
# @return [Array<Karafka::Messages::Message, Boolean>] message we may want to skip and
|
55
|
+
# information if this message was from marked offset or figured out via mom flow
|
56
|
+
def find_skippable_message
|
57
|
+
skippable_message = messages.find do |msg|
|
58
|
+
coordinator.marked? && msg.offset == coordinator.seek_offset
|
59
|
+
end
|
60
|
+
|
61
|
+
# If we don't have the message matching the last comitted offset, it means that
|
62
|
+
# user operates with manual offsets and we're beyond the batch in which things
|
63
|
+
# broke for the first time. Then we skip the first (as no markings) and we
|
64
|
+
# move on one by one.
|
65
|
+
skippable_message ? [skippable_message, true] : [messages.first, false]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Moves the broken message into a separate queue defined via the settings
|
69
|
+
# @private
|
70
|
+
# @param skippable_message [Karafka::Messages::Message] message we are skipping that also
|
71
|
+
# should go to the dlq topic
|
72
|
+
def dispatch_to_dlq(skippable_message)
|
73
|
+
producer.produce_async(
|
74
|
+
topic: topic.dead_letter_queue.topic,
|
75
|
+
payload: skippable_message.raw_payload
|
76
|
+
)
|
77
|
+
|
78
|
+
# Notify about dispatch on the events bus
|
79
|
+
Karafka.monitor.instrument(
|
80
|
+
'dead_letter_queue.dispatched',
|
81
|
+
caller: self,
|
82
|
+
message: skippable_message
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Processing
|
5
|
+
module Strategies
|
6
|
+
# Same as pure dead letter queue but we do not marked failed message as consumed
|
7
|
+
module DlqMom
|
8
|
+
include Dlq
|
9
|
+
|
10
|
+
# Apply strategy when dlq is on with manual offset management
|
11
|
+
FEATURES = %i[
|
12
|
+
dead_letter_queue
|
13
|
+
manual_offset_management
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
# When manual offset management is on, we do not mark anything as consumed automatically
|
17
|
+
# and we rely on the user to figure things out
|
18
|
+
def handle_after_consume
|
19
|
+
return if revoked?
|
20
|
+
|
21
|
+
if coordinator.success?
|
22
|
+
coordinator.pause_tracker.reset
|
23
|
+
elsif coordinator.pause_tracker.attempt <= topic.dead_letter_queue.max_retries
|
24
|
+
retry_after_pause
|
25
|
+
# If we've reached number of retries that we could, we need to skip the first message
|
26
|
+
# that was not marked as consumed, pause and continue, while also moving this message
|
27
|
+
# to the dead topic
|
28
|
+
else
|
29
|
+
# We reset the pause to indicate we will now consider it as "ok".
|
30
|
+
coordinator.pause_tracker.reset
|
31
|
+
|
32
|
+
skippable_message, = find_skippable_message
|
33
|
+
|
34
|
+
dispatch_to_dlq(skippable_message)
|
35
|
+
|
36
|
+
# Save the next offset we want to go with after moving given message to DLQ
|
37
|
+
# Without this, we would not be able to move forward and we would end up
|
38
|
+
# in an infinite loop trying to un-pause from the message we've already processed
|
39
|
+
# Of course, since it's a MoM a rebalance or kill, will move it back as no
|
40
|
+
# offsets are being committed
|
41
|
+
coordinator.seek_offset = skippable_message.offset + 1
|
42
|
+
|
43
|
+
pause(coordinator.seek_offset, nil, false)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|