lib/lolitra/handler_base.rb in lolitra-0.1.1 vs lib/lolitra/handler_base.rb in lolitra-0.1.2
- old
+ new
@@ -54,11 +54,12 @@
base.starters = []
base.is_stateful = false
end
def handle(message)
- #puts "#{self.name} try to handle new message #{message.class.name}"
+ Lolitra::logger.debug("Message recived: #{message.class.message_key}")
+ Lolitra::logger.debug("#{message}")
begin
get_handler(message).handle(message)
rescue NoMethodError => e
raise NoHandlerMessageException.new(self, message) if e.message == "undefined method `handle' for nil:NilClass"
raise
@@ -163,10 +164,12 @@
bus.pull_subscribe(message_class, handler_class)
end
end
def self.publish(message_instance)
+ Lolitra::logger.debug("Message sent: #{message.class.message_key}")
+ Lolitra::logger.debug("#{message.marshall}")
instance.publish(message_instance)
end
def publish(message_instance)
bus.publish(message_instance)
@@ -253,21 +256,17 @@
def pull_subscribe(message_class, handler_class)
create_queue(message_class, handler_class, {:durable => true}, queue_prefix + MessageHandler::Helpers.underscore(handler_class.name))
end
def publish(message)
- Lolitra::logger.debug("Message sent: #{message.class.message_key}")
- Lolitra::logger.debug("#{message.marshall}")
self.exchange.publish(message.marshall, :routing_key => message.class.message_key, :timestamp => Time.now.to_i)
end
private
def create_queue(message_class, handler_class, options, queue_name)
EM.next_tick do
channel = AMQP::Channel.new(self.connection)
channel.prefetch(1).queue(queue_name, options).bind(self.exchange, :routing_key => message_class.message_key).subscribe do |info, payload|
- Lolitra::logger.debug("Message recived: #{info.routing_key}")
- Lolitra::logger.debug("#{payload}")
message_class_tmp = handler_class.handlers[info.routing_key][0]
handler_class.handle(message_class_tmp.unmarshall(payload))
end
end
end