2
我試圖用ruby-smpp發送短信。繼工程實例和一些研究em-redis and eventmachine,我有以下gateway.rb配置:在ruby-smpp中用Eventmachine和EM-Redis發送郵件
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
messageSender,和將在該模塊:
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])
CompanyGateway.send_mt(message_hashed["from"],
message_hashed["to"],
message_hashed["message"])
end
EM.next_tick(&method(:next))
end
end
end
什麼工作:我啓動網關並連接到SMSC模擬器。我將消息添加到redis列表中,並且發送得很好。 什麼突破:現在已經有值在Redis的列表,並與下面的錯誤運行gateway.rb遊:
Exception in SMS Gateway: Transceiver is unbound. Cannot send MT messages. at /vagrant/lib/ruby-smpp/lib/smpp/transceiver.rb:28:in `send_mt'
/vagrant/lib/ruby-smpp/gateways/ucellgate.rb:87:in `send_mt'
/vagrant/lib/ruby-smpp/gateways/ucellgate.rb:66:in `block in next'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/em-hiredis-0.1.0/lib/em-hiredis/client.rb:149:in `block in method_missing'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:134:in `call'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:134:in `set_deferred_status'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:173:in `succeed'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/em-hiredis-0.1.0/lib/em-hiredis/client.rb:75:in `block in connect'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/em-hiredis-0.1.0/lib/em-hiredis/event_emitter.rb:8:in `call'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/em-hiredis-0.1.0/lib/em-hiredis/event_emitter.rb:8:in `block in emit'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/em-hiredis-0.1.0/lib/em-hiredis/event_emitter.rb:8:in `each'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/em-hiredis-0.1.0/lib/em-hiredis/event_emitter.rb:8:in `emit'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/em-hiredis-0.1.0/lib/em-hiredis/connection.rb:21:in `receive_data'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/vagrant/lib/ruby-smpp/gateways/ucellgate.rb:103:in `block in start'
/vagrant/lib/ruby-smpp/gateways/ucellgate.rb:102:in `loop'
/vagrant/lib/ruby-smpp/gateways/ucellgate.rb:102:in `start'
/vagrant/lib/ruby-smpp/gateways/ucellgate.rb:186:in `<main>'
我希望能夠不管運行Redis的列表的網關是空的或沒有,發送存儲的消息和將來到達列表中的消息。有什麼建議?
你說得對,謝謝! – Bek 2011-12-28 09:48:59