Skip to content

Instantly share code, notes, and snippets.

@theaboutbox
Created August 20, 2009 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theaboutbox/171326 to your computer and use it in GitHub Desktop.
Save theaboutbox/171326 to your computer and use it in GitHub Desktop.
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