Skip to content

Commit

Permalink
Merge pull request #6 from huangmj7/consumer
Browse files Browse the repository at this point in the history
Consumer
  • Loading branch information
Bad-Science authored Jun 28, 2018
2 parents e45f27c + aea359a commit 106aaaa
Show file tree
Hide file tree
Showing 9 changed files with 14,074 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RUN bundle install

COPY . $INSTALL_PATH

CMD ["ruby", "app.rb"]
CMD bundle exec karafka server
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

ruby '2.5.1'
gem 'karafka'

92 changes: 92 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (5.2.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
concurrent-ruby (1.0.5)
delivery_boy (0.2.6)
king_konf (~> 0.2)
ruby-kafka (~> 0.5)
dry-configurable (0.7.0)
concurrent-ruby (~> 1.0)
dry-container (0.6.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.4.6)
concurrent-ruby (~> 1.0)
dry-equalizer (0.2.1)
dry-events (0.1.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.4)
dry-equalizer (~> 0.2)
dry-inflector (0.1.2)
dry-logic (0.4.2)
dry-container (~> 0.2, >= 0.2.6)
dry-core (~> 0.2)
dry-equalizer (~> 0.2)
dry-monitor (0.1.2)
dry-configurable (~> 0.5)
dry-equalizer (~> 0.2)
dry-events (~> 0.1)
rouge (~> 2.0, >= 2.2.1)
dry-types (0.13.2)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.4, >= 0.4.4)
dry-equalizer (~> 0.2)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 0.4, >= 0.4.2)
dry-validation (0.12.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (~> 0.2, >= 0.2.1)
dry-equalizer (~> 0.2)
dry-logic (~> 0.4, >= 0.4.0)
dry-types (~> 0.13.1)
envlogic (1.1.0)
dry-inflector (~> 0.1)
i18n (1.0.1)
concurrent-ruby (~> 1.0)
karafka (1.2.4)
activesupport (>= 4.0)
dry-configurable (~> 0.7)
dry-inflector (~> 0.1.1)
dry-monitor (~> 0.1)
dry-validation (~> 0.11)
envlogic (~> 1.0)
multi_json (>= 1.12)
rake (>= 11.3)
require_all (>= 1.4)
ruby-kafka (>= 0.5.3)
thor (~> 0.19)
waterdrop (~> 1.2)
king_konf (0.3.6)
minitest (5.11.3)
multi_json (1.13.1)
null-logger (0.1.5)
rake (12.3.1)
require_all (2.0.0)
rouge (2.2.1)
ruby-kafka (0.6.7)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
waterdrop (1.2.2)
delivery_boy (~> 0.2)
dry-configurable (~> 0.7)
dry-monitor (~> 0.1)
dry-validation (~> 0.11)
null-logger (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
karafka

BUNDLED WITH
1.16.2
4 changes: 3 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
puts 'Hello, World'
require 'karafka'

puts 'Hello world'
7 changes: 7 additions & 0 deletions app/consumers/application_consumer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# Application consumer from which all Karafka consumers should inherit
# You can rename it if it would conflict with your current code base (in case you're integrating
# Karafka with other frameworks)
ApplicationConsumer = Class.new(Karafka::BaseConsumer)

8 changes: 8 additions & 0 deletions app/consumers/sections_consumer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'karafka'
require_relative 'application_consumer'

class SectionConsumer < ApplicationConsumer
def consume
puts params #print out the single message received
end
end
11 changes: 11 additions & 0 deletions app/responders/application_responder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

# Application responder from which all Karafka responders should inherit
# You can rename it if it would conflict with your current code base (in case you're integrating
# Karafka with other frameworks)
class ApplicationResponder < Karafka::BaseResponder
# This method needs to be implemented in each of the responders
# def respond(data)
# respond_to :topic, data.to_json
# end
end
43 changes: 43 additions & 0 deletions karafka.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true
#require 'karafka'
# Non Ruby on Rails setup
ENV['RACK_ENV'] ||= 'development'
ENV['KARAFKA_ENV'] ||= ENV['RACK_ENV']
require 'bundler/setup'
Bundler.require(:default, ENV['KARAFKA_ENV'])
Karafka::Loader.load(Karafka::App.root)
require_relative 'app/consumers/sections_consumer.rb'

# Ruby on Rails setup
# Remove whole non-Rails setup that is above and uncomment the 4 lines below
# ENV['RAILS_ENV'] ||= 'development'
# ENV['KARAFKA_ENV'] = ENV['RAILS_ENV']
# require ::File.expand_path('../config/environment', __FILE__)
# Rails.application.eager_load!
require 'karafka'

class KarafkaApp < Karafka::App
setup do |config|
config.kafka.seed_brokers = %w(kafka://kafka:9094)
config.client_id = 'notifications'
config.backend = :inline
config.batch_fetching = false
config.batch_consuming = false
# Uncomment this for Rails app integration
# config.logger = Rails.logger
end


after_init do |config|
end

Karafka.monitor.subscribe(Karafka::Instrumentation::Listener)
KarafkaApp.consumer_groups.draw do
consumer_group :notifications do
topic :section_change do
consumer SectionConsumer #Single message from section_change
end
end
end
end
KarafkaApp.boot!
Loading

0 comments on commit 106aaaa

Please sign in to comment.