Class: Karafka::Web::Management::Actions::CreateTopics
- Defined in:
- lib/karafka/web/management/actions/create_topics.rb
Overview
Creates all the needed topics (if they don’t exist). It does not populate data.
Instance Method Summary collapse
-
#call(replication_factor) ⇒ Object
Runs the creation process.
Instance Method Details
#call(replication_factor) ⇒ Object
Note:
The order of creation of those topics is important. In order to support the zero-downtime bootstrap, we use the presence of the states topic and its initial state existence as an indicator that the setup went as expected. It the consumers states topic exists and contains needed data, it means all went as expected and that topics created before it also exist (as no error).
Runs the creation process
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/karafka/web/management/actions/create_topics.rb', line 19 def call(replication_factor) consumers_states_topic = ::Karafka::Web.config.topics.consumers.states consumers_metrics_topic = ::Karafka::Web.config.topics.consumers.metrics consumers_reports_topic = ::Karafka::Web.config.topics.consumers.reports consumers_commands_topic = ::Karafka::Web.config.topics.consumers.commands errors_topic = ::Karafka::Web.config.topics.errors if existing_topics_names.include?(errors_topic.name) exists(errors_topic.name) else creating(errors_topic.name) # All the errors will be dispatched here # This topic can have multiple partitions but we go with one by default. A single # Ruby process should not crash that often and if there is an expectation of a higher # volume of errors, this can be changed by the end user ::Karafka::Admin.create_topic( errors_topic.name, 1, replication_factor, errors_topic.config ) created(errors_topic.name) end if existing_topics_names.include?(consumers_reports_topic.name) exists(consumers_reports_topic.name) else creating(consumers_reports_topic.name) # This topic needs to have one partition ::Karafka::Admin.create_topic( consumers_reports_topic.name, 1, replication_factor, consumers_reports_topic.config ) created(consumers_reports_topic.name) end if existing_topics_names.include?(consumers_metrics_topic.name) exists(consumers_metrics_topic.name) else creating(consumers_metrics_topic.name) # This topic needs to have one partition # Same as states - only most recent is relevant as it is a materialized state ::Karafka::Admin.create_topic( consumers_metrics_topic.name, 1, replication_factor, consumers_metrics_topic.config ) created(consumers_metrics_topic.name) end if existing_topics_names.include?(consumers_commands_topic.name) exists(consumers_commands_topic.name) else creating(consumers_commands_topic.name) # Commands are suppose to live short and be used for controlling processes and some # debug. Their data can be removed safely fast. ::Karafka::Admin.create_topic( consumers_commands_topic.name, 1, replication_factor, consumers_commands_topic.config ) created(consumers_commands_topic.name) end # Create only if needed if existing_topics_names.include?(consumers_states_topic.name) exists(consumers_states_topic.name) else creating(consumers_states_topic.name) # This topic needs to have one partition ::Karafka::Admin.create_topic( consumers_states_topic.name, 1, replication_factor, consumers_states_topic.config ) created(consumers_states_topic.name) end end |