-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from bdieu178/master
- Loading branch information
Showing
18 changed files
with
171,136 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
FROM ruby:2.5.1-alpine | ||
|
||
RUN apk add --update ruby-dev build-base | ||
RUN apk update && apk add bash | ||
|
||
ENV INSTALL_PATH /usr/src/app/ | ||
RUN mkdir -p $INSTALL_PATH | ||
|
||
WORKDIR $INSTALL_PATH | ||
|
||
COPY Gemfile Gemfile.lock $INSTALL_PATH | ||
COPY Gemfile $INSTALL_PATH | ||
RUN bundle install | ||
|
||
COPY . $INSTALL_PATH | ||
|
||
CMD bundle exec karafka server | ||
CMD ["/bin/sh","entrypoint.sh"] | ||
#make an entrypoint.sh for executing iodine & karafka server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
YACS Event Stream Websocket API | ||
--- | ||
Implemented using Kafka & Plezi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,52 @@ | ||
require 'karafka' | ||
require 'plezi' | ||
require 'iodine' | ||
require_relative 'app/controllers/eventstream' | ||
|
||
puts 'Hello world' | ||
## Set environment, working directory, load gems and create logs | ||
#ENV['ENV'] ||= ENV['RACK_ENV'] ||= ENV['RAILS_ENV'] # production ENV will render SASS as compressed. | ||
## Using pathname extentions for setting public folder | ||
require 'pathname' | ||
## Set up root object, it might be used by the environment and\or the plezi extension gems. | ||
Root ||= Pathname.new(File.dirname(__FILE__)).expand_path | ||
## If this app is independant, use bundler to load gems (including the plezi gem). | ||
## otherwise, use the original app's Gemfile and Plezi will automatically switch to Rack mode. | ||
require 'bundler' | ||
Bundler.require(:default, ENV['ENV'].to_s.to_sym) | ||
# Load all the code from a subfolder called 'app' | ||
Dir[File.join '{controllers}', '**', '*.rb'].each { |file| load File.expand_path(file) } | ||
# Load all the code from a subfolder called 'lib' | ||
Dir[File.join '{lib}', '**', '*.rb'].each { |file| load File.expand_path(file) } | ||
|
||
|
||
#Setting the port | ||
#Iodine::DEFAULT_HTTP_ARGS[:port] = 4860 | ||
|
||
## Logging | ||
#::Iodine::DEFAULT_HTTP_ARGS[:log] = 1 if ::Iodine::DEFAULT_HTTP_ARGS[:log].nil? | ||
#Iodine::DEFAULT_HTTP_ARGS[:public] ||= './public' | ||
|
||
|
||
# # Optional Scaling (across processes or machines): | ||
ENV['PL_REDIS_URL'] ||= ENV['REDIS_URL'] || | ||
ENV['REDISCLOUD_URL'] || | ||
ENV['REDISTOGO_URL'] || | ||
nil # "redis://:[email protected]:6389/0" | ||
# # redis channel name should be changed IF using the same Plezi code within | ||
# # more then one application (i.e., using both Rails and Plezi together). | ||
# Plezi.app_name = 'yacs_websocket_a027e2d668a7dc21c59fe56f018432ea' | ||
|
||
# Map the views folder to the template root (for the {#render} function). | ||
#Plezi.templates = Root.join('views').to_s | ||
|
||
# load routes. | ||
load Root.join('routes.rb').to_s | ||
|
||
App = Proc.new do |env| | ||
if(env['rack.upgrade?'.freeze] == :websocket) | ||
env['rack.upgrade'.freeze] = EventStream.new | ||
[0, {}, []] | ||
else | ||
[200, {"Content-Length" => "12", "Content-Type" => "text/plain"}, ["Hello World!"]] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'karafka' | ||
require 'iodine' | ||
require_relative 'application_consumer' | ||
|
||
class CourseConsumer < ApplicationConsumer | ||
def consume | ||
unless params.nil? | ||
@notifications = params.to_s | ||
::Iodine::publish channel: "notifications", message: "#{@notifications}" | ||
puts "SectionsConsumer sent message to websocket" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
require 'karafka' | ||
require 'iodine' | ||
require_relative 'application_consumer' | ||
|
||
class SectionConsumer < ApplicationConsumer | ||
def consume | ||
puts params #print out the single message received | ||
end | ||
def consume | ||
unless params.nil? | ||
@notifications = params.to_s | ||
::Iodine::publish channel: "notifications", message: "#{@notifications}" | ||
puts "SectionsConsumer sent message to websocket" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'plezi' | ||
require 'iodine' | ||
|
||
class EventStream | ||
#@auto_dispatch = true | ||
def index | ||
render 'client' | ||
end | ||
|
||
def on_open | ||
puts "WS connection open" | ||
::Iodine::subscribe channel:"notifications" do | ||
puts "I'm in!" | ||
end | ||
end | ||
|
||
#TODO | ||
def on_message data | ||
#::Iodine::write "#{@data}" | ||
#puts data | ||
end | ||
|
||
def on_close | ||
::Iodine::unsubscribe("notifications") | ||
end | ||
end | ||
#test location: ws://localhost:3000/notifications/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Default Rack interface | ||
# encoding: UTF-8 | ||
# load the application | ||
load ::File.expand_path(File.join('..', 'app.rb'), __FILE__) | ||
|
||
run App | ||
run Plezi.app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nohup bundler exec iodine -p 4860 -www ./public -v > iodine.out 2>&1 & | ||
bundle exec karafka server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
* Listening on port 4860 | ||
|
||
Server is running 2 workers X 2 threads, press ^C to stop | ||
Running Plezi version: 0.15.1 | ||
|
||
Starting up Iodine HTTP Server on port 4860: | ||
* Ruby v.2.5.1 | ||
* Iodine v.0.4.19 | ||
* 1048576 max concurrent connections / open files | ||
* Serving static files from ./public | ||
|
||
* 6 is running. | ||
* 14 is running. | ||
172.18.0.1 - - [Tue, 6 Aug 2018 03:14:14 GMT] "GET /notifications HTTP/1.1" 101 -- 300ms | ||
Iodine caught an unprotected exception - LocalJumpError: no block given | ||
/usr/src/app/app/controllers/eventstream.rb:12:in `subscribe' | ||
/usr/src/app/app/controllers/eventstream.rb:12:in `on_open' | ||
Iodine caught an unprotected exception - TypeError: wrong argument type String (expected Hash) | ||
/usr/src/app/app/controllers/eventstream.rb:26:in `publish' | ||
/usr/src/app/app/controllers/eventstream.rb:26:in `on_close' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.