Sha256: 5858b330416341815281d0c62b455ee42dc2e531020cb00c32009cab0ad000f5
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true module Karafka # Namespace for all elements related to requests routing module Routing # Karafka framework Router for routing incoming messages to proper controllers # @note Since Kafka does not provide namespaces or modules for topics, they all have "flat" # structure so all the routes are being stored in a single level array module Router # Builds a controller instance that should handle message from a given topic # @param topic_id [String] topic based on which we find a proper route # @return [Karafka::BaseController] base controller descendant instance object def build(topic_id) topic = find(topic_id) topic.controller.new.tap { |ctrl| ctrl.topic = topic } end private # @return [Karafka::Routing::Route] proper route details # @raise [Karafka::Topic::NonMatchingTopicError] raised if topic name does not match # any route defined by user using routes.draw def find(topic_id) App.consumer_groups.each do |consumer_group| consumer_group.topics.each do |topic| return topic if topic.id == topic_id end end raise(Errors::NonMatchingRouteError, topic_id) end module_function :build module_function :find end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
karafka-0.6.0.rc2 | lib/karafka/routing/router.rb |
karafka-0.6.0.rc1 | lib/karafka/routing/router.rb |