Created
August 20, 2009 20:15
-
-
Save theaboutbox/171326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageSender | |
def initialize | |
@conn = Stomp::Connection.open(USER,PASSWORD,HOST,PORT) | |
@conn.subscribe(Messaging::DESTINATION, { :ack =>"auto" }) | |
end | |
def processing_loop | |
while true do | |
msg = @conn.receive | |
begin | |
Messaging.process_messages(msg.body) | |
rescue => detail | |
send_error(msg,detail) | |
end | |
end | |
end | |
def keepalive | |
msg = Hash.new | |
msg[:command] = :ping | |
msg[:reply] = true | |
msg[:str] = 'keepalive' | |
while true do | |
sleep 60 | |
msg[:time] = Time.now | |
@conn.send Messaging::DESTINATION, msg.to_yaml | |
end | |
end | |
def send_error(msg,detail) | |
# redacted | |
end | |
def self.run | |
@instance = MessageSender.new | |
Thread.new(@instance) {|instance| instance.keepalive} | |
@instance.processing_loop | |
end | |
def time_str | |
Time.now.strftime("%Y-%m-%d %H:%M:%S") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment