Skip to content

Commit

Permalink
Resolved issue YACS-RCOS#7 & YACS-RCOS#8
Browse files Browse the repository at this point in the history
  • Loading branch information
bdieu178 committed Jul 25, 2018
1 parent 5dcacf2 commit 2c84367
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions app/app/consumers/courses_consumer.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/app/consumers/sections_consumer.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 10 additions & 6 deletions app/app/controllers/eventstream.rb
Original file line number Diff line number Diff line change
@@ -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
#Plezi.route '/notifications', EventStream
#ip address 172.19.0.9:9094
2 changes: 1 addition & 1 deletion app/controllers/eventstream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c84367

Please sign in to comment.