From 2c84367df886c831e759215ffad6dd11428dbdea Mon Sep 17 00:00:00 2001 From: bdieu178 Date: Tue, 24 Jul 2018 21:08:37 -0400 Subject: [PATCH] Resolved issue #7 & #8 --- app/app/consumers/courses_consumer.rb | 5 +++-- app/app/consumers/sections_consumer.rb | 5 +++-- app/app/controllers/eventstream.rb | 16 ++++++++++------ app/controllers/eventstream.rb | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/app/consumers/courses_consumer.rb b/app/app/consumers/courses_consumer.rb index 2a6b09b..f7a076a 100644 --- a/app/app/consumers/courses_consumer.rb +++ b/app/app/consumers/courses_consumer.rb @@ -1,13 +1,14 @@ require 'karafka' -require_relative 'application_consumer' require 'plezi' +require 'iodine' +require_relative 'application_consumer' class CourseConsumer < ApplicationConsumer def consume if ( Object.const_defined?('EventStream') == false ) puts "EventStream class not initialized" else - EventStream.on_message(params) + EventStream.new.notify(params) puts "Consumer message sent to websocket" end end diff --git a/app/app/consumers/sections_consumer.rb b/app/app/consumers/sections_consumer.rb index fb090f6..5088919 100644 --- a/app/app/consumers/sections_consumer.rb +++ b/app/app/consumers/sections_consumer.rb @@ -1,13 +1,14 @@ require 'karafka' -require_relative 'application_consumer' require 'plezi' +require 'iodine' +require_relative 'application_consumer' class SectionConsumer < ApplicationConsumer def consume if ( Object.const_defined?('EventStream') == false ) puts "EventStream class not initialized" else - EventStream.on_message(params) + EventStream.new.notify(params) puts "Consumer message sent to websocket" end end diff --git a/app/app/controllers/eventstream.rb b/app/app/controllers/eventstream.rb index 1d456a8..33b33a3 100644 --- a/app/app/controllers/eventstream.rb +++ b/app/app/controllers/eventstream.rb @@ -1,19 +1,23 @@ require 'plezi' +require 'iodine' require 'json' class EventStream - + #@auto_dispatch = true + def on_open puts 'Opened the YACS-EventStream Websocket!' end - ## When receiving a single message from Consumer pusblish to socket - def on_message(data) - event = {:notifications => :data } - write event.to_json + #def on_message data + def notify(data) + puts data + #event = {:notifications => data } + #puts event.to_json # need to figure out this shit end def on_close end end -Plezi.route '/notifications', EventStream \ No newline at end of file +#Plezi.route '/notifications', EventStream +#ip address 172.19.0.9:9094 \ No newline at end of file diff --git a/app/controllers/eventstream.rb b/app/controllers/eventstream.rb index 3f96693..d44e7b0 100644 --- a/app/controllers/eventstream.rb +++ b/app/controllers/eventstream.rb @@ -7,7 +7,7 @@ def on_open end ## When receiving a single message from Consumer pusblish to socket - def on_message(data) + def on_message data unless write { notifications: :data }.to_json write "no message sent" end