-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Pull Request for Issue #7 #8 ( Bryan + Minja) #9
Changes from 12 commits
7c645e7
084cbbe
e030a7f
c3290c0
8ff6750
101537c
ca538a6
4246ff4
3a71374
f5ad690
abf0d94
7eb0f74
dd13d80
5dcacf2
2c84367
a0f109c
766c3e5
892561d
426bb75
946ee4d
af7090a
74ae4b7
aabe503
4eed4ea
e7c3ec6
ff77fb0
7273e43
727d8c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
YACS Event Stream Websocket API | ||
--- | ||
Implemented using Kafka & Plezi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,35 @@ | ||
require 'karafka' | ||
# encoding: UTF-8 | ||
|
||
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) } | ||
|
||
## Logging | ||
Iodine::DEFAULT_HTTP_ARGS[:log] = 1 if Iodine::DEFAULT_HTTP_ARGS[:log].nil? | ||
|
||
# # 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'karafka' | ||
require_relative 'application_consumer' | ||
require 'eventstream' | ||
|
||
class CourseConsumer < ApplicationConsumer | ||
def consume | ||
if ( Object.const_defined?('EventStream') == false ) | ||
puts "EventStream class not initialized" | ||
else | ||
EventStream.on_message(params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cannot call |
||
puts "Consumer message sent to websocket" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
require 'karafka' | ||
require_relative 'application_consumer' | ||
require 'eventstream' | ||
|
||
class SectionConsumer < ApplicationConsumer | ||
def consume | ||
puts params #print out the single message received | ||
end | ||
def consume | ||
if ( Object.const_defined?('EventStream') == false ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, not sure why we need this check |
||
puts "EventStream class not initialized" | ||
else | ||
EventStream.on_message(params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you cannot call |
||
puts "Consumer message sent to websocket" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'plezi' | ||
|
||
class EventStream | ||
|
||
def on_open | ||
puts 'Opened the YACS-EventStream Websocket!' | ||
end | ||
|
||
## When receiving a single message from Consumer pusblish to socket | ||
def on_message(data) | ||
unless write { notifications: :data }.to_json | ||
write "no message sent" | ||
end | ||
end | ||
|
||
def on_close | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Default Rack interface | ||
|
||
# load the application | ||
load ::File.expand_path(File.join('..', 'app.rb'), __FILE__) | ||
|
||
Iodine::DEFAULT_HTTP_ARGS[:public] ||= './public' | ||
|
||
run Plezi.app |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# load all application code and gems | ||
require 'bundler' | ||
Bundler.require(:default, ENV['ENV'].to_s.to_sym) | ||
# set Plezi to rake mode and load it's tasks (if relevant). | ||
Plezi.no_autostart | ||
|
||
# Add your tasks |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## | ||
# ws://0.0.0.0/EventStream | ||
Plezi.route '/', EventStream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this check needed?