Skip to content

Instantly share code, notes, and snippets.

@Bek
Created December 28, 2011 04:31
Show Gist options
  • Save Bek/1526274 to your computer and use it in GitHub Desktop.
Save Bek/1526274 to your computer and use it in GitHub Desktop.
module MessageSender
def self.redis
@redis ||= EM::Hiredis.connect
end
def self.next
redis.blpop("company-out", 0) do |item|
if item[1]
message_hashed = JSON.parse(item[1])
puts "this is the problematic hash #{message_hashed}"
UcellGateway.send_mt(message_hashed["from"],
message_hashed["to"],
message_hashed["message"])
end
EM.next_tick(&method(:next))
end
end
end
loop do
EventMachine::run do
@@tx = EventMachine::connect(
config[:host],
config[:port],
Smpp::Transceiver,
config,
self # delegate that will receive callbacks on MOs and DRs and other events
)
MessageSender.next # gets the messages from redis list and sends at each click of the EventMachine
end
puts "Disconnected. Reconnecting in 5 seconds.."
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment