karafka 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.console_irbrc +13 -0
  3. data/.github/ISSUE_TEMPLATE.md +2 -0
  4. data/.gitignore +68 -0
  5. data/.rspec +1 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/.travis.yml +17 -0
  9. data/CHANGELOG.md +371 -0
  10. data/CODE_OF_CONDUCT.md +46 -0
  11. data/CONTRIBUTING.md +42 -0
  12. data/Gemfile +12 -0
  13. data/Gemfile.lock +111 -0
  14. data/MIT-LICENCE +18 -0
  15. data/README.md +95 -0
  16. data/bin/karafka +19 -0
  17. data/config/errors.yml +6 -0
  18. data/karafka.gemspec +35 -0
  19. data/lib/karafka.rb +68 -0
  20. data/lib/karafka/app.rb +52 -0
  21. data/lib/karafka/attributes_map.rb +67 -0
  22. data/lib/karafka/backends/inline.rb +17 -0
  23. data/lib/karafka/base_controller.rb +60 -0
  24. data/lib/karafka/base_responder.rb +185 -0
  25. data/lib/karafka/cli.rb +54 -0
  26. data/lib/karafka/cli/base.rb +78 -0
  27. data/lib/karafka/cli/console.rb +29 -0
  28. data/lib/karafka/cli/flow.rb +46 -0
  29. data/lib/karafka/cli/info.rb +29 -0
  30. data/lib/karafka/cli/install.rb +43 -0
  31. data/lib/karafka/cli/server.rb +67 -0
  32. data/lib/karafka/connection/config_adapter.rb +112 -0
  33. data/lib/karafka/connection/consumer.rb +121 -0
  34. data/lib/karafka/connection/listener.rb +51 -0
  35. data/lib/karafka/connection/processor.rb +61 -0
  36. data/lib/karafka/controllers/callbacks.rb +54 -0
  37. data/lib/karafka/controllers/includer.rb +51 -0
  38. data/lib/karafka/controllers/responders.rb +19 -0
  39. data/lib/karafka/controllers/single_params.rb +15 -0
  40. data/lib/karafka/errors.rb +43 -0
  41. data/lib/karafka/fetcher.rb +48 -0
  42. data/lib/karafka/helpers/class_matcher.rb +78 -0
  43. data/lib/karafka/helpers/config_retriever.rb +46 -0
  44. data/lib/karafka/helpers/multi_delegator.rb +33 -0
  45. data/lib/karafka/loader.rb +29 -0
  46. data/lib/karafka/logger.rb +53 -0
  47. data/lib/karafka/monitor.rb +98 -0
  48. data/lib/karafka/params/params.rb +128 -0
  49. data/lib/karafka/params/params_batch.rb +41 -0
  50. data/lib/karafka/parsers/json.rb +38 -0
  51. data/lib/karafka/patches/dry_configurable.rb +31 -0
  52. data/lib/karafka/patches/ruby_kafka.rb +34 -0
  53. data/lib/karafka/persistence/consumer.rb +25 -0
  54. data/lib/karafka/persistence/controller.rb +38 -0
  55. data/lib/karafka/process.rb +63 -0
  56. data/lib/karafka/responders/builder.rb +35 -0
  57. data/lib/karafka/responders/topic.rb +57 -0
  58. data/lib/karafka/routing/builder.rb +61 -0
  59. data/lib/karafka/routing/consumer_group.rb +61 -0
  60. data/lib/karafka/routing/consumer_mapper.rb +33 -0
  61. data/lib/karafka/routing/proxy.rb +37 -0
  62. data/lib/karafka/routing/router.rb +29 -0
  63. data/lib/karafka/routing/topic.rb +66 -0
  64. data/lib/karafka/routing/topic_mapper.rb +55 -0
  65. data/lib/karafka/schemas/config.rb +21 -0
  66. data/lib/karafka/schemas/consumer_group.rb +65 -0
  67. data/lib/karafka/schemas/consumer_group_topic.rb +18 -0
  68. data/lib/karafka/schemas/responder_usage.rb +39 -0
  69. data/lib/karafka/schemas/server_cli_options.rb +43 -0
  70. data/lib/karafka/server.rb +62 -0
  71. data/lib/karafka/setup/config.rb +163 -0
  72. data/lib/karafka/setup/configurators/base.rb +35 -0
  73. data/lib/karafka/setup/configurators/water_drop.rb +29 -0
  74. data/lib/karafka/status.rb +25 -0
  75. data/lib/karafka/templates/application_controller.rb.example +7 -0
  76. data/lib/karafka/templates/application_responder.rb.example +11 -0
  77. data/lib/karafka/templates/karafka.rb.example +41 -0
  78. data/lib/karafka/version.rb +7 -0
  79. data/log/.gitkeep +0 -0
  80. metadata +267 -0
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at maciej@coditsu.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,42 @@
1
+ # Contribute
2
+
3
+ ## Introduction
4
+
5
+ First, thank you for considering contributing to karafka! It's people like you that make the open source community such a great community! 😊
6
+
7
+ We welcome any type of contribution, not only code. You can help with
8
+ - **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open)
9
+ - **Marketing**: writing blog posts, howto's, printing stickers, ...
10
+ - **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
11
+ - **Code**: take a look at the [open issues](issues). Even if you can't write code, commenting on them, showing that you care about a given issue matters. It helps us triage them.
12
+ - **Money**: we welcome financial contributions in full transparency on our [open collective](https://opencollective.com/karafka).
13
+
14
+ ## Your First Contribution
15
+
16
+ Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).
17
+
18
+ ## Submitting code
19
+
20
+ Any code change should be submitted as a pull request. The description should explain what the code does and give steps to execute it. The pull request should also contain tests.
21
+
22
+ ## Code review process
23
+
24
+ The bigger the pull request, the longer it will take to review and merge. Try to break down large pull requests in smaller chunks that are easier to review and merge.
25
+ It is also always helpful to have some context for your pull request. What was the purpose? Why does it matter to you?
26
+
27
+ ## Financial contributions
28
+
29
+ We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/karafka).
30
+ Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed.
31
+
32
+ ## Questions
33
+
34
+ If you have any questions, create an [issue](issue) (protip: do a quick search first to see if someone else didn't ask the same question before!).
35
+ You can also reach us at hello@karafka.opencollective.com.
36
+
37
+ ## Credits
38
+
39
+ ### Contributors
40
+
41
+ Thank you to all the people who have already contributed to karafka!
42
+ <a href="graphs/contributors"><img src="https://opencollective.com/karafka/contributors.svg?width=890" /></a>
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development, :test do
8
+ gem 'waterdrop'
9
+ gem 'timecop'
10
+ gem 'rspec'
11
+ gem 'simplecov'
12
+ end
@@ -0,0 +1,111 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ karafka (1.1.0)
5
+ activesupport (>= 5.0)
6
+ dry-configurable (~> 0.7)
7
+ dry-validation (~> 0.11)
8
+ envlogic (~> 1.0)
9
+ multi_json (>= 1.12)
10
+ rake (>= 11.3)
11
+ require_all (>= 1.4)
12
+ ruby-kafka (>= 0.5)
13
+ thor (~> 0.19)
14
+ waterdrop (>= 1.0.1)
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ activesupport (5.1.4)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (~> 0.7)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ concurrent-ruby (1.0.5)
25
+ delivery_boy (0.2.2)
26
+ king_konf (~> 0.1.8)
27
+ ruby-kafka (~> 0.4)
28
+ diff-lcs (1.3)
29
+ docile (1.1.5)
30
+ dry-configurable (0.7.0)
31
+ concurrent-ruby (~> 1.0)
32
+ dry-container (0.6.0)
33
+ concurrent-ruby (~> 1.0)
34
+ dry-configurable (~> 0.1, >= 0.1.3)
35
+ dry-core (0.4.1)
36
+ concurrent-ruby (~> 1.0)
37
+ dry-equalizer (0.2.0)
38
+ dry-logic (0.4.2)
39
+ dry-container (~> 0.2, >= 0.2.6)
40
+ dry-core (~> 0.2)
41
+ dry-equalizer (~> 0.2)
42
+ dry-types (0.12.2)
43
+ concurrent-ruby (~> 1.0)
44
+ dry-configurable (~> 0.1)
45
+ dry-container (~> 0.3)
46
+ dry-core (~> 0.2, >= 0.2.1)
47
+ dry-equalizer (~> 0.2)
48
+ dry-logic (~> 0.4, >= 0.4.2)
49
+ inflecto (~> 0.0.0, >= 0.0.2)
50
+ dry-validation (0.11.1)
51
+ concurrent-ruby (~> 1.0)
52
+ dry-configurable (~> 0.1, >= 0.1.3)
53
+ dry-core (~> 0.2, >= 0.2.1)
54
+ dry-equalizer (~> 0.2)
55
+ dry-logic (~> 0.4, >= 0.4.0)
56
+ dry-types (~> 0.12.0)
57
+ envlogic (1.0.4)
58
+ activesupport
59
+ i18n (0.9.1)
60
+ concurrent-ruby (~> 1.0)
61
+ inflecto (0.0.2)
62
+ json (2.1.0)
63
+ king_konf (0.1.8)
64
+ minitest (5.10.3)
65
+ multi_json (1.12.2)
66
+ null-logger (0.1.4)
67
+ rake (12.2.1)
68
+ require_all (1.4.0)
69
+ rspec (3.7.0)
70
+ rspec-core (~> 3.7.0)
71
+ rspec-expectations (~> 3.7.0)
72
+ rspec-mocks (~> 3.7.0)
73
+ rspec-core (3.7.0)
74
+ rspec-support (~> 3.7.0)
75
+ rspec-expectations (3.7.0)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.7.0)
78
+ rspec-mocks (3.7.0)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.7.0)
81
+ rspec-support (3.7.0)
82
+ ruby-kafka (0.5.0)
83
+ simplecov (0.15.1)
84
+ docile (~> 1.1.0)
85
+ json (>= 1.8, < 3)
86
+ simplecov-html (~> 0.10.0)
87
+ simplecov-html (0.10.2)
88
+ thor (0.20.0)
89
+ thread_safe (0.3.6)
90
+ timecop (0.9.1)
91
+ tzinfo (1.2.4)
92
+ thread_safe (~> 0.1)
93
+ waterdrop (1.0.1)
94
+ delivery_boy (>= 0.2.2)
95
+ dry-configurable (~> 0.7)
96
+ dry-validation (~> 0.11)
97
+ null-logger
98
+ ruby-kafka (>= 0.5)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ karafka!
105
+ rspec
106
+ simplecov
107
+ timecop
108
+ waterdrop
109
+
110
+ BUNDLED WITH
111
+ 1.15.4
@@ -0,0 +1,18 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining
2
+ a copy of this software and associated documentation files (the
3
+ "Software"), to deal in the Software without restriction, including
4
+ without limitation the rights to use, copy, modify, merge, publish,
5
+ distribute, sublicense, and/or sell copies of the Software, and to
6
+ permit persons to whom the Software is furnished to do so, subject to
7
+ the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,95 @@
1
+ ![karafka logo](https://raw.githubusercontent.com/karafka/misc/master/logo/karafka_logotype_transparent2.png)
2
+
3
+ [![Build Status](https://travis-ci.org/karafka/karafka.svg?branch=master)](https://travis-ci.org/karafka/karafka)
4
+
5
+ Framework used to simplify Apache Kafka based Ruby applications development.
6
+
7
+ It allows programmers to use approach similar to standard HTTP conventions (```params``` and ```params_batch```) when working with asynchronous Kafka messages.
8
+
9
+ Karafka not only handles incoming messages but also provides tools for building complex data-flow applications that receive and send messages.
10
+
11
+ ## How does it work
12
+
13
+ Karafka provides a higher-level abstraction that allows you to focus on your business logic development, instead of focusing on implementing lower level abstraction layers. It provides developers with a set of tools that are dedicated for building multi-topic applications similarly to how Rails applications are being built.
14
+
15
+ ### Some things you might wonder about:
16
+
17
+ - You can integrate Karafka with any Ruby based application.
18
+ - Karafka does **not** require Sidekiq or any other third party software (apart from Kafka itself).
19
+ - Karafka works with Ruby on Rails but it is a standalone framework that can work without it.
20
+ - Karafka has a minimal set of dependencies, so adding it won't be a huge burden for your already existing applications.
21
+
22
+ Karafka based applications can be easily deployed to any type of infrastructure, including those based on:
23
+
24
+ * Heroku
25
+ * Capistrano
26
+ * Docker
27
+
28
+ ## Support
29
+
30
+ Karafka has a [Wiki pages](https://github.com/karafka/karafka/wiki) for almost everything and a pretty decent [FAQ](https://github.com/karafka/karafka/wiki/FAQ). It covers the whole installation, setup and deployment along with other useful details on how to run Karafka.
31
+
32
+ If you have any questions about using Karafka, feel free to join our [Gitter](https://gitter.im/karafka/karafka) chat channel.
33
+
34
+ ## Getting started
35
+
36
+ If you want to get started with Kafka and Karafka as fast as possible, then the best idea is to just clone our example repository:
37
+
38
+ ```bash
39
+ git clone https://github.com/karafka/karafka-example-app ./example_app
40
+ ```
41
+
42
+ then, just bundle install all the dependencies:
43
+
44
+ ```bash
45
+ cd ./example_app
46
+ bundle install
47
+ ```
48
+
49
+ and follow the instructions from the [example app Wiki](https://github.com/karafka/karafka-example-app/blob/master/README.md).
50
+
51
+ **Note**: you need to ensure, that you have Kafka up and running and you need to configure Kafka seed_brokers in the ```karafka.rb``` file.
52
+
53
+ If you need more details and know how on how to start Karafka with a clean installation, read the [Getting started page](https://github.com/karafka/karafka/wiki/Getting-started) section of our Wiki.
54
+
55
+ ## Notice
56
+
57
+ Karafka framework and Karafka team are __not__ related to Kafka streaming service called CloudKarafka in any matter. We don't recommend nor discourage usage of their platform.
58
+
59
+ ## References
60
+
61
+ * [Karafka framework](https://github.com/karafka/karafka)
62
+ * [Karafka Travis CI](https://travis-ci.org/karafka/karafka)
63
+ * [Karafka Coditsu](https://app.coditsu.io/karafka/repositories/karafka)
64
+
65
+ ## Note on Patches/Pull Requests
66
+
67
+ Fork the project.
68
+ Make your feature addition or bug fix.
69
+ Add tests for it. This is important so we don't break it in a future versions unintentionally.
70
+ Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull). Send me a pull request. Bonus points for topic branches.
71
+
72
+ [![coditsu](https://coditsu.io/assets/quality_bar.svg)](https://app.coditsu.io/karafka/repositories/karafka)
73
+
74
+ Each pull request must pass our quality requirements. To check if everything is as it should be, we use [Coditsu](https://coditsu.io) that combines multiple linters and code analyzers for both code and documentation.
75
+
76
+ Unfortunately, it does not yet support independent forks, however you should be fine by looking at what we require.
77
+
78
+ Please run:
79
+
80
+ ```bash
81
+ bundle exec rspec
82
+ ```
83
+
84
+ to check if everything is in order. After that you can submit a pull request.
85
+
86
+ ## Contributors
87
+
88
+ This project exists thanks to all the people who contribute.
89
+ <a href="https://github.com/karafka/karafka/graphs/contributors"><img src="https://opencollective.com/karafka/contributors.svg?width=890" /></a>
90
+
91
+ ## Sponsors
92
+
93
+ We are looking for sustainable sponsorship. If your company is relying on Karafka framework or simply want to see Karafka evolve faster to meet your requirements, please consider backing the project.
94
+
95
+ Please contact [Maciej Mensfeld](mailto:maciej@coditsu.io) directly for more details.
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'karafka'
4
+
5
+ # If there is a boot file, we need to require it as we expect it to contain
6
+ # Karafka app setup, routes, etc
7
+ if File.exist?(Karafka.boot_file)
8
+ require Karafka.boot_file.to_s
9
+ else
10
+ # However when it is unavailable, we still want to be able to run help command
11
+ # and install command as they don't require configured app itself to run
12
+ raise(
13
+ Karafka::Errors::MissingBootFile,
14
+ Karafka.boot_file
15
+ ) unless %w[-h install].include?(ARGV[0])
16
+ end
17
+
18
+ Karafka::Cli.prepare
19
+ Karafka::Cli.start
@@ -0,0 +1,6 @@
1
+ en:
2
+ errors:
3
+ broker_schema?: >
4
+ has an invalid format.
5
+ Expected schema, host and port number.
6
+ Example: kafka://127.0.0.1:9092 or kafka+ssl://127.0.0.1:9092
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'karafka/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'karafka'
10
+ spec.version = ::Karafka::VERSION
11
+ spec.platform = Gem::Platform::RUBY
12
+ spec.authors = ['Maciej Mensfeld', 'Pavlo Vavruk', 'Adam Gwozdowski']
13
+ spec.email = %w[maciej@coditsu.io pavlo.vavruk@gmail.com adam99g@gmail.com]
14
+ spec.homepage = 'https://github.com/karafka/karafka'
15
+ spec.summary = 'Ruby based framework for working with Apache Kafka'
16
+ spec.description = 'Framework used to simplify Apache Kafka based Ruby applications development'
17
+ spec.license = 'MIT'
18
+
19
+ spec.add_dependency 'activesupport', '>= 5.0'
20
+ spec.add_dependency 'dry-configurable', '~> 0.7'
21
+ spec.add_dependency 'dry-validation', '~> 0.11'
22
+ spec.add_dependency 'envlogic', '~> 1.0'
23
+ spec.add_dependency 'multi_json', '>= 1.12'
24
+ spec.add_dependency 'rake', '>= 11.3'
25
+ spec.add_dependency 'require_all', '>= 1.4'
26
+ spec.add_dependency 'ruby-kafka', '>= 0.5'
27
+ spec.add_dependency 'thor', '~> 0.19'
28
+ spec.add_dependency 'waterdrop', '>= 1.0.1'
29
+
30
+ spec.required_ruby_version = '>= 2.3.0'
31
+
32
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
33
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
34
+ spec.require_paths = %w[lib]
35
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[
4
+ English
5
+ waterdrop
6
+ kafka
7
+ envlogic
8
+ thor
9
+ fileutils
10
+ multi_json
11
+ require_all
12
+ dry-configurable
13
+ dry-validation
14
+ active_support/callbacks
15
+ active_support/core_ext/hash/indifferent_access
16
+ active_support/descendants_tracker
17
+ active_support/inflector
18
+ karafka/loader
19
+ ].each(&method(:require))
20
+
21
+ # Karafka library
22
+ module Karafka
23
+ extend Envlogic
24
+
25
+ class << self
26
+ # @return [Logger] logger that we want to use. Will use ::Karafka::Logger by default
27
+ def logger
28
+ @logger ||= App.config.logger
29
+ end
30
+
31
+ # @return [::Karafka::Monitor] monitor that we want to use. Will use dummy monitor by default
32
+ def monitor
33
+ @monitor ||= App.config.monitor
34
+ end
35
+
36
+ # @return [String] root path of this gem
37
+ def gem_root
38
+ Pathname.new(File.expand_path('../..', __FILE__))
39
+ end
40
+
41
+ # @return [String] Karafka app root path (user application path)
42
+ def root
43
+ Pathname.new(ENV['KARAFKA_ROOT_DIR'] || File.dirname(ENV['BUNDLE_GEMFILE']))
44
+ end
45
+
46
+ # @return [String] path to Karafka gem root core
47
+ def core_root
48
+ Pathname.new(File.expand_path('../karafka', __FILE__))
49
+ end
50
+
51
+ # @return [String] path to a default file that contains booting procedure etc
52
+ # @note By default it is a file called 'karafka.rb' but it can be specified as you wish if you
53
+ # have Karafka that is merged into a Sinatra/Rails app and karafka.rb is taken.
54
+ # It will be used for console/controllers/etc
55
+ # @example Standard only-Karafka case
56
+ # Karafka.boot_file #=> '/home/app_path/karafka.rb'
57
+ # @example Non standard case
58
+ # KARAFKA_BOOT_FILE='/home/app_path/app.rb'
59
+ # Karafka.boot_file #=> '/home/app_path/app.rb'
60
+ def boot_file
61
+ Pathname.new(ENV['KARAFKA_BOOT_FILE'] || File.join(Karafka.root, 'karafka.rb'))
62
+ end
63
+ end
64
+ end
65
+
66
+ Karafka::Loader.load!(Karafka.core_root)
67
+ Kafka::Consumer.prepend(Karafka::Patches::RubyKafka)
68
+ Dry::Configurable::Config.prepend(Karafka::Patches::DryConfigurable)