smsc_manager 0.4.8 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/bin/internal_sms_load_test.rb +124 -0
- data/bin/send_sms.rb +1 -0
- data/bin/send_sms_load_test.rb +28 -2
- data/bin/sms_om_server.rb +1 -1
- data/bin/sms_topic_server.rb +1 -1
- data/lib/smsc_manager/broadcast_topic.rb +5 -4
- data/lib/smsc_manager/sms_send_topic.rb +15 -4
- data/lib/smsc_manager/smsc_listener.rb +10 -10
- data/lib/smsc_manager/version.rb +2 -2
- metadata +4 -2
data/Manifest.txt
CHANGED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
def usage
|
4
|
+
puts "Usage: internal_sms_load_test.rb -u user -m msisdn -s source -t text -c count -r count"
|
5
|
+
puts "to test how long to send c sms"
|
6
|
+
exit
|
7
|
+
end
|
8
|
+
def parse_options(params)
|
9
|
+
opts = OptionParser.new
|
10
|
+
puts "argv are #{params}"
|
11
|
+
#params_split = params.split(' ')
|
12
|
+
#puts "paramsp is #{paramsp}"
|
13
|
+
user_flag=msisdn_flag=source_flag=text_flag=count_flag=true
|
14
|
+
temp_hash = {}
|
15
|
+
opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val
|
16
|
+
puts "user is #{val}"
|
17
|
+
user_flag=false }
|
18
|
+
opts.on("-h","--host VAL", String) {|val| temp_hash[:host ] = val
|
19
|
+
puts "host is #{val}"
|
20
|
+
}
|
21
|
+
|
22
|
+
opts.on("-c","--count VAL", Integer) {|val| temp_hash[:count ] = val
|
23
|
+
puts "count is #{val}"
|
24
|
+
count_flag=false }
|
25
|
+
opts.on("-m","--msisdn VAL", String) {|val| temp_hash[:msisdn ] = val
|
26
|
+
puts "msiddn is #{val}"
|
27
|
+
msisdn_flag=false }
|
28
|
+
opts.on("-r","--repeat VAL", Integer) {|val| temp_hash[:repeat ] = val
|
29
|
+
puts "repease is #{val}"
|
30
|
+
msisdn_flag=false }
|
31
|
+
|
32
|
+
opts.on("-s","--source VAL", String) {|val| temp_hash[:source ] = val
|
33
|
+
puts "source is #{val}"
|
34
|
+
source_flag=false }
|
35
|
+
opts.on("-t","--text VAL", String) {|val| temp_hash[:text ] = val
|
36
|
+
puts "text is #{val}"
|
37
|
+
text_flag=false }
|
38
|
+
#opts.on("-d","--database VAL", String) {|val| temp_hash[:db ] = val }
|
39
|
+
#opts.on("-p","--password VAL", String) {|val| temp_hash[:password ] = val }
|
40
|
+
#opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val }
|
41
|
+
#puts " in test commander option parse #{port} #{url}"
|
42
|
+
opts.parse(params)
|
43
|
+
# puts " in HTTP #{hostname} port #{port} url: #{url}"
|
44
|
+
usage if user_flag or msisdn_flag or source_flag or text_flag or count_flag
|
45
|
+
return temp_hash
|
46
|
+
end
|
47
|
+
arg_hash=parse_options(ARGV)
|
48
|
+
require 'pp'
|
49
|
+
|
50
|
+
require 'rubygems'
|
51
|
+
gem 'smsc_manager'
|
52
|
+
require 'smsc_manager'
|
53
|
+
def send_group(arg_hash,sms_sender)
|
54
|
+
user=arg_hash[:user]
|
55
|
+
destination=arg_hash[:msisdn]
|
56
|
+
source=arg_hash[:source]
|
57
|
+
text=arg_hash[:text]
|
58
|
+
count=arg_hash[:count]
|
59
|
+
receipt_count=count
|
60
|
+
1.upto(count) { |c|
|
61
|
+
puts "sent #{c} messages" if c % 100 == 0
|
62
|
+
final_text = "count: #{c}: #{text} "
|
63
|
+
s=SmscManager::Sms.new(final_text,destination,source)
|
64
|
+
sms_sender.send_topic_sms_receipt(s) { |m| receipt_count-=1
|
65
|
+
# puts "receipt: #{receipt_count}"
|
66
|
+
}
|
67
|
+
sleep(1) if c % 100 == 0
|
68
|
+
Thread.pass
|
69
|
+
}
|
70
|
+
|
71
|
+
# sms_sender.close_topic
|
72
|
+
begin
|
73
|
+
Timeout::timeout(count*0.5) {
|
74
|
+
while true
|
75
|
+
puts "sent #{count} waiting for #{receipt_count} receipts"
|
76
|
+
exit(0) if receipt_count==0
|
77
|
+
sleep(1)
|
78
|
+
end }
|
79
|
+
rescue SystemExit
|
80
|
+
|
81
|
+
rescue Exception => e
|
82
|
+
puts "exception #{e.message} class: #{e.class}"
|
83
|
+
puts "#{e.backtrace}"
|
84
|
+
raise e
|
85
|
+
|
86
|
+
end
|
87
|
+
receipt_count
|
88
|
+
end
|
89
|
+
puts "Finding sms topic to use:"
|
90
|
+
begin
|
91
|
+
sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
|
92
|
+
# sms_sender.setup_auto_close #only call this once # servers onlycall cloase
|
93
|
+
rescue Exception => e
|
94
|
+
puts "exception found #{e.backtrace}"
|
95
|
+
end
|
96
|
+
|
97
|
+
repeat= arg_hash[:repeat]
|
98
|
+
count= arg_hash[:count]
|
99
|
+
start=Time.now
|
100
|
+
puts "Time now: #{start}"
|
101
|
+
no_receipt_count=0
|
102
|
+
1.upto(repeat) { |r|
|
103
|
+
no_receipt_count+=send_group(arg_hash,sms_sender)
|
104
|
+
sleep(1)
|
105
|
+
|
106
|
+
}
|
107
|
+
|
108
|
+
diff = Time.now - start
|
109
|
+
no_prob = count*repeat - no_receipt_count
|
110
|
+
puts "#{Time.now} Sent #{count*repeat} in #{diff} seconds with #{no_receipt_count} problems";
|
111
|
+
puts " Average message per second is: #{no_prob/diff}"
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
exit(0)
|
116
|
+
|
117
|
+
# puts "Sending user: #{user} destination: #{destination} text: #{text}"
|
118
|
+
# res= smsc.send(sms)
|
119
|
+
# puts "Response code: #{res.response} body: #{res.response_body}"
|
120
|
+
# puts "Response code: #{res}" if res.kind_of? String
|
121
|
+
# puts "pretty print response:"
|
122
|
+
# pp res
|
123
|
+
# puts "Response code: #{res.} body: #{res.code}" if res.kind_of? Net::Http
|
124
|
+
|
data/bin/send_sms.rb
CHANGED
@@ -56,6 +56,7 @@ require 'smsc_manager'
|
|
56
56
|
text=arg_hash[:text]
|
57
57
|
sms_sender.send_sms(text,destination,source)
|
58
58
|
puts "Sending user: #{user} destination: #{destination} text: #{text}"
|
59
|
+
#sms_sender.setup_auto_close
|
59
60
|
# res= smsc.send(sms)
|
60
61
|
# puts "Response code: #{res.response} body: #{res.response_body}"
|
61
62
|
# puts "Response code: #{res}" if res.kind_of? String
|
data/bin/send_sms_load_test.rb
CHANGED
@@ -60,14 +60,40 @@ require 'smsc_manager'
|
|
60
60
|
count=arg_hash[:count]
|
61
61
|
start=Time.now
|
62
62
|
puts "Time now: #{start}"
|
63
|
+
receipt_count=count
|
63
64
|
1.upto(count) { |c|
|
64
65
|
puts "sent #{c} messages" if c % 100 == 0
|
65
66
|
final_text = "count: #{c}: #{text} "
|
66
|
-
|
67
|
+
s=SmscManager::Sms.new(final_text,destination,source)
|
68
|
+
sms_sender.send_topic_sms_receipt(s) { |m| receipt_count-=1
|
69
|
+
# puts "receipt: #{receipt_count}"
|
70
|
+
}
|
71
|
+
sleep(1) if c % 100 == 0
|
72
|
+
Thread.pass
|
67
73
|
}
|
68
74
|
diff = Time.now - start
|
69
|
-
|
75
|
+
# sms_sender.close_topic
|
76
|
+
begin
|
77
|
+
Timeout::timeout(count*0.5) {
|
78
|
+
while true
|
79
|
+
puts "sent #{count} waiting for #{receipt_count} receipts"
|
80
|
+
exit(0) if receipt_count==0
|
81
|
+
sleep(1)
|
82
|
+
end }
|
83
|
+
rescue SystemExit
|
84
|
+
|
85
|
+
rescue Exception => e
|
86
|
+
puts "exception #{e.message} class: #{e.class}"
|
87
|
+
puts "no receipt"
|
88
|
+
# raise "timeout"
|
89
|
+
ensure
|
90
|
+
sms_sender.setup_auto_close
|
91
|
+
end
|
92
|
+
|
93
|
+
|
70
94
|
puts "#{Time.now} Sent #{count} in #{diff} seconds";
|
95
|
+
exit(0)
|
96
|
+
|
71
97
|
# puts "Sending user: #{user} destination: #{destination} text: #{text}"
|
72
98
|
# res= smsc.send(sms)
|
73
99
|
# puts "Response code: #{res.response} body: #{res.response_body}"
|
data/bin/sms_om_server.rb
CHANGED
@@ -12,7 +12,7 @@ require 'smsc_manager'
|
|
12
12
|
puts "Starting Operational Measurement (OM) server:"
|
13
13
|
# begin
|
14
14
|
# can add additional options to change host/port etc
|
15
|
-
sms_listener=SmscManager::SmsStatisticsListener.new({:topic => '/topic/sms'}).run
|
15
|
+
sms_listener=SmscManager::SmsStatisticsListener.new({:topic => '/topic/sms', :thread_count => '5'}).run
|
16
16
|
# sms_listener.join
|
17
17
|
# rescue Exception => e
|
18
18
|
puts "exception found #{e.backtrace}"
|
data/bin/sms_topic_server.rb
CHANGED
@@ -11,7 +11,7 @@ require 'smsc_manager'
|
|
11
11
|
|
12
12
|
puts "Starting topic server:"
|
13
13
|
# begin
|
14
|
-
SmscManager::SmscListener.new({:topic => '/topic/sms'}).run
|
14
|
+
SmscManager::SmscListener.new({:topic => '/topic/sms', :thread_count => '14'}).run
|
15
15
|
# sms_listener.join
|
16
16
|
# rescue Exception => e
|
17
17
|
puts "exception found #{e.backtrace}"
|
@@ -45,20 +45,21 @@ class BroadcastTopic
|
|
45
45
|
# puts " dst is #{dst}"
|
46
46
|
}
|
47
47
|
puts "populate topic sent #{self.sent}"
|
48
|
-
|
48
|
+
sleep(1)
|
49
|
+
self.sms_sender.disconnect_stomp
|
49
50
|
end
|
50
51
|
def send_it(txt,dst)
|
51
52
|
# puts "hello from send it"
|
52
53
|
begin
|
53
54
|
sms=SmscManager::Sms.new(txt,dst,self.source)
|
54
|
-
self.sms_sender.
|
55
|
+
self.sms_sender.send_topic_sms_receipt(sms) {|r| # puts "in receipt handler #{r.to_s}"
|
56
|
+
self.sent+=1 }
|
55
57
|
self.attempts+=1
|
56
|
-
self.sent+=1
|
57
58
|
rescue Exception => e
|
58
59
|
self.sent-=1
|
59
60
|
puts "bad values dst: #{dst} txt: #{txt} msg: #{e.message}"
|
60
61
|
end
|
61
|
-
|
62
|
+
# self.sms_sender.close_topic
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
@@ -7,7 +7,7 @@ require 'stomp_message'
|
|
7
7
|
# This sends the sms to a activemq topic
|
8
8
|
module SmscManager
|
9
9
|
class SmsSendTopic < StompMessage::StompSendTopic
|
10
|
-
|
10
|
+
|
11
11
|
#need to define topic, host properly
|
12
12
|
@@TOPIC='/topic/sms'
|
13
13
|
# must be defined as method in sms_listener
|
@@ -15,9 +15,10 @@ class SmsSendTopic < StompMessage::StompSendTopic
|
|
15
15
|
def initialize(options={})
|
16
16
|
# set up variables using hash
|
17
17
|
options[:topic] = options[:topic]==nil ? @@TOPIC : options[:topic]
|
18
|
-
|
18
|
+
|
19
19
|
super(options)
|
20
|
-
|
20
|
+
|
21
|
+
#puts "finished initializing"
|
21
22
|
end
|
22
23
|
# def initialize()
|
23
24
|
# self.conn = Stomp::Connection.open '', '', 'localhost', 61613, false
|
@@ -33,9 +34,19 @@ class SmsSendTopic < StompMessage::StompSendTopic
|
|
33
34
|
# msgbody=sms.to_xml
|
34
35
|
m=StompMessage::Message.new(@@STOMP_SMS_MESSAGE, sms.to_xml)
|
35
36
|
# puts "message body is #{msgbody}"
|
36
|
-
|
37
|
+
# headers = {:msisdn =>"#{sms.destination}"}
|
38
|
+
headers = {}
|
37
39
|
send_topic(m, headers)
|
38
40
|
end #send_sms
|
41
|
+
def send_topic_sms_receipt(sms, &r_block)
|
42
|
+
#sms=SmscManager::Sms.new(text,destination,source)
|
43
|
+
# msgbody=sms.to_xml
|
44
|
+
m=StompMessage::Message.new(@@STOMP_SMS_MESSAGE, sms.to_xml)
|
45
|
+
# puts "message body is #{msgbody}"
|
46
|
+
# headers = {:msisdn =>"#{sms.destination}"}
|
47
|
+
headers = {}
|
48
|
+
send_topic(m, headers, &r_block)
|
49
|
+
end #send_sms
|
39
50
|
# simple script to show xml message
|
40
51
|
def self.create_stomp_message(txt,dest,src)
|
41
52
|
sms=SmscManager::Sms.new(txt,dest,src)
|
@@ -17,23 +17,23 @@ class SmscListener < StompMessage::StompServer
|
|
17
17
|
self.smsc=SmscManager::SmscConnection.factory
|
18
18
|
puts "finished initializing"
|
19
19
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
# def send_reply(headers,msg)
|
21
|
+
# msisdn = headers['msisdn']
|
22
|
+
# reply_topic=headers['reply-to']
|
23
|
+
# puts "headers: #{headers['msisdn']} reply topic #{headers['reply-to']}"
|
24
|
+
# internal_conn = Stomp::Connection.open '', '', self.host, self.port, false
|
25
|
+
# internal_conn.subscribe reply_topic, { :ack =>"auto" }
|
26
26
|
# m=StompMessage::Message.new('stomp_REPLY', msg_body)
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
# internal_conn.send(reply_topic, msg.to_xml, {'persistent'=>'false', 'msisdn' => "#{msisdn}" })
|
28
|
+
# internal_conn.unsubscribe reply_topic
|
29
|
+
# end
|
30
30
|
# name is message command
|
31
31
|
def stomp_SMS(msg, stomp_msg)
|
32
32
|
sms=SmscManager::Sms.load_xml(msg.body)
|
33
33
|
puts "sending sms #{msg.body}" if @debug
|
34
34
|
res= self.smsc.send(sms)
|
35
35
|
|
36
|
-
|
36
|
+
# sleep(SLEEP_TIME) #only 5 messages per second max
|
37
37
|
end
|
38
38
|
|
39
39
|
end # smsc listener
|
data/lib/smsc_manager/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: smsc_manager
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-10-
|
6
|
+
version: 0.5.1
|
7
|
+
date: 2007-10-08 00:00:00 +08:00
|
8
8
|
summary: connection to smsc via http using kannel
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- bin/smsc_print_config.rb
|
40
40
|
- bin/send_sms_post.rb
|
41
41
|
- bin/send_sms.rb
|
42
|
+
- bin/internal_sms_load_test.rb
|
42
43
|
- bin/send_sms_load_test.rb
|
43
44
|
- bin/sms_print_xml.rb
|
44
45
|
- bin/send_sms_http.rb
|
@@ -73,6 +74,7 @@ executables:
|
|
73
74
|
- smsc_print_config.rb
|
74
75
|
- send_sms_post.rb
|
75
76
|
- send_sms.rb
|
77
|
+
- internal_sms_load_test.rb
|
76
78
|
- send_sms_load_test.rb
|
77
79
|
- sms_print_xml.rb
|
78
80
|
- send_sms_http.rb
|