smsc_manager 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.txt
CHANGED
@@ -2,6 +2,8 @@ require 'yaml'
|
|
2
2
|
require 'rubygems'
|
3
3
|
gem 'stomp'
|
4
4
|
require 'stomp'
|
5
|
+
gem 'stomp_message'
|
6
|
+
require 'stomp_message'
|
5
7
|
# This sends the sms to a activemq topic
|
6
8
|
module SmscManager
|
7
9
|
class SmsSendTopic
|
@@ -28,9 +30,10 @@ class SmsSendTopic
|
|
28
30
|
end #send_sms
|
29
31
|
def send_topic(sms)
|
30
32
|
#sms=SmscManager::Sms.new(text,destination,source)
|
31
|
-
|
33
|
+
# msgbody=sms.to_xml
|
34
|
+
m=StompMessage::Message.new('stomp_SMS', sms.to_xml)
|
32
35
|
# puts "message body is #{msgbody}"
|
33
|
-
self.conn.send @@TOPIC,
|
36
|
+
self.conn.send @@TOPIC, m.to_xml, {'persistent'=>'false'}
|
34
37
|
end #send_sms
|
35
38
|
end # smsc listener
|
36
39
|
|
@@ -2,17 +2,21 @@ require 'yaml'
|
|
2
2
|
require 'rubygems'
|
3
3
|
gem 'stomp'
|
4
4
|
require 'stomp'
|
5
|
-
|
5
|
+
gem 'stomp_message'
|
6
|
+
require 'stomp_message'
|
6
7
|
module SmscManager
|
7
8
|
class SmsStatisticsListener
|
8
9
|
@@MAX_THROUGHPUT =5 # in messages per second
|
9
|
-
attr_accessor :conn, :count, :source
|
10
|
+
attr_accessor :conn, :count, :source, :topic
|
10
11
|
#need to define topic, host properly
|
11
|
-
|
12
|
+
|
13
|
+
@debug=false
|
12
14
|
def initialize
|
15
|
+
self.topic='/topic/sms'
|
16
|
+
puts "in intialize topic #{self.topic}"
|
13
17
|
self.conn = Stomp::Connection.open '', '', 'localhost', 61613, false
|
14
18
|
self.count = 0
|
15
|
-
self.conn.subscribe
|
19
|
+
self.conn.subscribe self.topic, { :ack =>"auto" }
|
16
20
|
self.source ={}
|
17
21
|
puts "finished initializing"
|
18
22
|
end
|
@@ -21,13 +25,28 @@ class SmsStatisticsListener
|
|
21
25
|
self.source[sms.source] = 0 if !self.source.key?(sms.source)
|
22
26
|
self.source[sms.source] += 1
|
23
27
|
end
|
24
|
-
def
|
25
|
-
puts "
|
28
|
+
def stomp_REPORT(msg)
|
29
|
+
puts "#{self.topic} OM Report: #{Time.now}"
|
26
30
|
puts "message count is: #{count}"
|
27
31
|
self.source.each_pair {|i,val|
|
28
32
|
puts " source #{i} count #{val}"
|
29
33
|
}
|
30
34
|
end
|
35
|
+
def stomp_SMS(msg)
|
36
|
+
puts "msg command #{msg.command} msg body #{msg.body}"
|
37
|
+
sms=SmscManager::Sms.load_xml(msg.body)
|
38
|
+
statistics(sms)
|
39
|
+
puts "#{self.topic} OM report stomp_SMS" if @debug
|
40
|
+
stomp_REPORT(msg) if self.count % 100 == 0
|
41
|
+
end
|
42
|
+
def stomp_DEBUG(msg)
|
43
|
+
@debug=!@debug
|
44
|
+
puts "debug flag is now #{@debug}"
|
45
|
+
end
|
46
|
+
def method_missing(name, *args)
|
47
|
+
puts "Method missing called: #{name}"
|
48
|
+
puts "Likely invalid message recived"
|
49
|
+
end
|
31
50
|
def run
|
32
51
|
# Thread.new {
|
33
52
|
while true #loop forever
|
@@ -35,12 +54,14 @@ class SmsStatisticsListener
|
|
35
54
|
msg = self.conn.receive
|
36
55
|
# puts "after receive"
|
37
56
|
begin
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
57
|
+
puts "STOMP message frame is : #{msg} "
|
58
|
+
m=StompMessage::Message.load_xml(msg.body)
|
59
|
+
# puts "Message is: #{m.to_xml}" if @debug
|
60
|
+
puts "Message type is #{m.command}" if @debug
|
61
|
+
self.send(m.command,m)
|
42
62
|
rescue Exception => e
|
43
|
-
puts "exception found #{e.backtrace}"
|
63
|
+
puts "exception found #{e.backtrace}"
|
64
|
+
puts "exception messae #{e.msg}"
|
44
65
|
end
|
45
66
|
end # while
|
46
67
|
# }
|
@@ -2,7 +2,9 @@ require 'yaml'
|
|
2
2
|
require 'rubygems'
|
3
3
|
gem 'stomp'
|
4
4
|
require 'stomp'
|
5
|
-
|
5
|
+
require 'stomp'
|
6
|
+
gem 'stomp_message'
|
7
|
+
require 'stomp_message'
|
6
8
|
module SmscManager
|
7
9
|
class SmscListener
|
8
10
|
@@MAX_THROUGHPUT =5 # in messages per second
|
@@ -10,6 +12,7 @@ class SmscListener
|
|
10
12
|
attr_accessor :conn, :smsc, :count
|
11
13
|
#need to define topic, host properly
|
12
14
|
@@TOPIC='/topic/sms'
|
15
|
+
@debug=false
|
13
16
|
def initialize
|
14
17
|
self.conn = Stomp::Connection.open '', '', 'localhost', 61613, false
|
15
18
|
self.count = 0
|
@@ -17,16 +20,34 @@ class SmscListener
|
|
17
20
|
self.smsc=SmscManager::SmscConnection.factory
|
18
21
|
puts "finished initializing"
|
19
22
|
end
|
23
|
+
# name is message command
|
24
|
+
def stomp_SMS(msg)
|
25
|
+
sms=SmscManager::Sms.load_xml(msg.body)
|
26
|
+
puts "sending sms #{msg.body}"
|
27
|
+
res= self.smsc.send(sms)
|
28
|
+
|
29
|
+
sleep(SLEEP_TIME) #only 5 messages per second max
|
30
|
+
end
|
31
|
+
def stomp_DEBUG(msg)
|
32
|
+
@debug=!@debug
|
33
|
+
puts "debug flag is now #{@debug}"
|
34
|
+
end
|
35
|
+
def method_missing(name, *args)
|
36
|
+
puts "Method missing called: #{name}"
|
37
|
+
puts "Likely invalid message recived"
|
38
|
+
end
|
20
39
|
def run
|
21
40
|
|
22
41
|
while true #loop forever
|
23
42
|
# puts "before receive"
|
24
43
|
msg = self.conn.receive
|
25
44
|
# puts "after receive"
|
26
|
-
begin
|
27
|
-
|
28
|
-
|
29
|
-
|
45
|
+
begin
|
46
|
+
# puts "STOMP message frame is : #{msg} " if @debug
|
47
|
+
m=StompMessage::Message.load_xml(msg.body)
|
48
|
+
# puts "Message is: #{m.to_xml}" if @debug
|
49
|
+
puts "Message type is #{m.command}" if @debug
|
50
|
+
self.send(m.command,m) # effectively case statement (Should SCREEN HERE)
|
30
51
|
# puts "sms text is: #{sms.text} dest is: #{sms.destination} result is: #{res}"
|
31
52
|
rescue Exception => e
|
32
53
|
puts "exception found #{e.backtrace}"
|
data/lib/smsc_manager/version.rb
CHANGED