Class: Lolitra::FayeBus

Inherits:
Object
  • Object
show all
Defined in:
lib/lolitra/handler_base.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FayeBus

Returns a new instance of FayeBus.



273
274
275
276
277
# File 'lib/lolitra/handler_base.rb', line 273

def initialize(options = {})
  EM::next_tick do
    @socketClient = Faye::Client.new(options[:url] || 'http://localhost:9292/faye')
  end
end

Instance Method Details

#publish(message) ⇒ Object



289
290
291
# File 'lib/lolitra/handler_base.rb', line 289

def publish(message)
  @socketClient.publish(message.class.message_key, message.marshall)
end

#subscribe(message_class, handler_class) ⇒ Object



279
280
281
282
283
284
285
286
287
# File 'lib/lolitra/handler_base.rb', line 279

def subscribe(message_class, handler_class)
  EM::next_tick do
    @socketClient.subscribe(message_class.message_key) do |payload|
      Lolitra::logger.debug("Message recived:")
      Lolitra::logger.debug("#{payload}")
      handler_class.handle(message_class.unmarshall(payload))
    end
  end
end