cli-proton-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/cli-proton-ruby-connector +23 -0
- data/bin/cli-proton-ruby-receiver +23 -0
- data/bin/cli-proton-ruby-sender +23 -0
- data/lib/connector_client.rb +50 -0
- data/lib/constants.rb +27 -0
- data/lib/defaults.rb +91 -0
- data/lib/formatters.rb +28 -0
- data/lib/formatters/basic_formatter.rb +112 -0
- data/lib/formatters/dict_formatter.rb +66 -0
- data/lib/formatters/interop_formatter.rb +88 -0
- data/lib/handlers.rb +34 -0
- data/lib/handlers/basic_handler.rb +79 -0
- data/lib/handlers/connector_handler.rb +90 -0
- data/lib/handlers/receiver_handler.rb +230 -0
- data/lib/handlers/sender_handler.rb +269 -0
- data/lib/handlers/sr_common_handler.rb +100 -0
- data/lib/options.rb +38 -0
- data/lib/options/basic_option_parser.rb +169 -0
- data/lib/options/connector_option_parser.rb +61 -0
- data/lib/options/receiver_option_parser.rb +154 -0
- data/lib/options/sender_option_parser.rb +365 -0
- data/lib/options/sr_common_option_parser.rb +96 -0
- data/lib/receiver_client.rb +61 -0
- data/lib/sender_client.rb +69 -0
- data/lib/utils/duration.rb +44 -0
- data/lib/utils/env_utils.rb +39 -0
- data/lib/utils/exit_timer.rb +44 -0
- data/lib/utils/string_utils.rb +81 -0
- metadata +98 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2017 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require_relative 'basic_option_parser'
|
18
|
+
|
19
|
+
module Options
|
20
|
+
|
21
|
+
# Option parser of basic (see Options::BasicOptionParser) and specific
|
22
|
+
# options for connector client
|
23
|
+
# ==== Specific connector options
|
24
|
+
# count:: number of connections to create (default: DEFAULT_COUNT,
|
25
|
+
# see Defaults)
|
26
|
+
class ConnectorOptionParser < Options::BasicOptionParser
|
27
|
+
|
28
|
+
# Initialization and parsing of basic and specific connector options
|
29
|
+
# ==== Parameters
|
30
|
+
# args:: arguments to parse
|
31
|
+
def initialize(args)
|
32
|
+
# Initialization of basic options
|
33
|
+
super()
|
34
|
+
# Connector usage
|
35
|
+
@opt_parser.banner = "Usage: <connector_program> [OPTIONS]"
|
36
|
+
|
37
|
+
# Connector specific options with default values
|
38
|
+
|
39
|
+
# Number of connections option
|
40
|
+
@options.count = Defaults::DEFAULT_COUNT
|
41
|
+
|
42
|
+
# Number of messages
|
43
|
+
@opt_parser.on(
|
44
|
+
"-c",
|
45
|
+
"--count COUNT",
|
46
|
+
Integer,
|
47
|
+
"number of connections to create "+
|
48
|
+
"(default: #{Defaults::DEFAULT_COUNT})"
|
49
|
+
) do |count|
|
50
|
+
@options.count = count
|
51
|
+
end
|
52
|
+
|
53
|
+
# Parse basic and specific options for connector client
|
54
|
+
parse(args)
|
55
|
+
end
|
56
|
+
|
57
|
+
end # class ConnectorOptionParser
|
58
|
+
|
59
|
+
end # module Options
|
60
|
+
|
61
|
+
# eof
|
@@ -0,0 +1,154 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2017 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require_relative 'sr_common_option_parser'
|
18
|
+
require_relative '../constants'
|
19
|
+
require_relative '../utils/string_utils'
|
20
|
+
|
21
|
+
module Options
|
22
|
+
|
23
|
+
# Option parser of basic (see Options::BasicOptionParser),
|
24
|
+
# common (see Options::SRCommonOptionParser)
|
25
|
+
# and specific options for receiver client
|
26
|
+
# ==== Specific receiver options
|
27
|
+
# count:: number of messages to receiver
|
28
|
+
# (default: DEFAULT_COUNT, see Defaults)
|
29
|
+
# process-reply-to:: send message to reply-to address if enabled
|
30
|
+
# and message got reply-to address
|
31
|
+
# recv-browse:: browse messages instead of reading
|
32
|
+
# (default: DEFAULT_BROWSE, see Defaults)
|
33
|
+
class ReceiverOptionParser < Options::SRCommonOptionParser
|
34
|
+
|
35
|
+
# Initialization and parsing of basic, common and specific receiver
|
36
|
+
# options
|
37
|
+
# ==== Parameters
|
38
|
+
# args:: arguments to parse
|
39
|
+
def initialize(args)
|
40
|
+
# Initialization of basic and common options
|
41
|
+
super()
|
42
|
+
# Receiver usage
|
43
|
+
@opt_parser.banner = "Usage: <receiver_program> [OPTIONS]"
|
44
|
+
|
45
|
+
# Receiver specific options with default values
|
46
|
+
|
47
|
+
# Number of messages option
|
48
|
+
@options.count = Defaults::DEFAULT_COUNT
|
49
|
+
# Credit for messages to be pre-fetched
|
50
|
+
@options.prefetch = Defaults::DEFAULT_PREFETCH
|
51
|
+
# Process reply to
|
52
|
+
@options.process_reply_to = Defaults::DEFAULT_PROC_REPLY_TO
|
53
|
+
# Browse messages
|
54
|
+
@options.browse = Defaults::DEFAULT_BROWSE
|
55
|
+
# Filter using selector
|
56
|
+
@options.selector = Defaults::DEFAULT_SELECTOR
|
57
|
+
# Receiver listen
|
58
|
+
@options.recv_listen = Defaults::DEFAULT_RECV_LISTEN
|
59
|
+
# Receiver listen port
|
60
|
+
@options.recv_listen_port = Defaults::DEFAULT_RECV_LISTEN_PORT
|
61
|
+
|
62
|
+
# Number of messages
|
63
|
+
@opt_parser.on(
|
64
|
+
"-c",
|
65
|
+
"--count COUNT",
|
66
|
+
Integer,
|
67
|
+
"number of messages to receiver "+
|
68
|
+
"(default: #{Defaults::DEFAULT_COUNT})"
|
69
|
+
) do |count|
|
70
|
+
@options.count = count
|
71
|
+
end
|
72
|
+
|
73
|
+
# Prefetch
|
74
|
+
@opt_parser.on(
|
75
|
+
"--reactor-prefetch PREFETCH",
|
76
|
+
Integer,
|
77
|
+
"receiver's prefetch count "+
|
78
|
+
"(default: #{Defaults::DEFAULT_PREFETCH})"
|
79
|
+
) do |prefetch|
|
80
|
+
@options.prefetch = prefetch
|
81
|
+
end
|
82
|
+
|
83
|
+
# Process reply to
|
84
|
+
@opt_parser.on(
|
85
|
+
"--process-reply-to",
|
86
|
+
"send message to reply-to address if enable and message got reply-to "+
|
87
|
+
"address",
|
88
|
+
) do |process_reply_to|
|
89
|
+
@options.process_reply_to = process_reply_to
|
90
|
+
end
|
91
|
+
|
92
|
+
# Browse messages
|
93
|
+
@opt_parser.on(
|
94
|
+
"--recv-browse",
|
95
|
+
"browse messages instead of reading",
|
96
|
+
) do |browse|
|
97
|
+
@options.browse = browse
|
98
|
+
end
|
99
|
+
|
100
|
+
# Filter messages
|
101
|
+
@opt_parser.on(
|
102
|
+
"--recv-selector SELECTOR",
|
103
|
+
"filter messages using a selector"
|
104
|
+
) do |selector|
|
105
|
+
@options.selector = selector
|
106
|
+
end
|
107
|
+
|
108
|
+
# Receiver listen
|
109
|
+
@opt_parser.on(
|
110
|
+
"--recv-listen LISTEN",
|
111
|
+
Options::BOOLEAN_STRINGS,
|
112
|
+
"enable receiver listen (P2P) (#{Options::BOOLEAN_STRINGS.join("/")}, "+
|
113
|
+
"default: #{Defaults::DEFAULT_RECV_LISTEN})"
|
114
|
+
) do |recv_listen|
|
115
|
+
@options.recv_listen = StringUtils.str_to_bool(recv_listen)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Receiver listen port
|
119
|
+
@opt_parser.on(
|
120
|
+
"--recv-listen-port PORT",
|
121
|
+
Integer,
|
122
|
+
"define port for local listening "+
|
123
|
+
"(range: #{Constants::CONST_MIN_PORT_RANGE_VALUE}-"+
|
124
|
+
"#{Constants::CONST_MAX_PORT_RANGE_VALUE}, "+
|
125
|
+
"default: #{Defaults::DEFAULT_RECV_LISTEN_PORT})"
|
126
|
+
) do |recv_listen_port|
|
127
|
+
if recv_listen_port < Constants::CONST_MIN_PORT_RANGE_VALUE \
|
128
|
+
or recv_listen_port > Constants::CONST_MAX_PORT_RANGE_VALUE
|
129
|
+
raise OptionParser::InvalidArgument, "#{recv_listen_port} "+
|
130
|
+
"(out of range: #{Constants::CONST_MIN_PORT_RANGE_VALUE}-"+
|
131
|
+
"#{Constants::CONST_MAX_PORT_RANGE_VALUE})"
|
132
|
+
end
|
133
|
+
@options.recv_listen_port = recv_listen_port
|
134
|
+
end
|
135
|
+
|
136
|
+
# Duration mode
|
137
|
+
@options.duration_mode = "before-receive"
|
138
|
+
duration_modes = %w(before-receive after-receive after-receive-action after-receive-tx-action)
|
139
|
+
@opt_parser.on(
|
140
|
+
"--duration-mode MODE", duration_modes,
|
141
|
+
"in use with --duration defines where to wait (allowed: #{duration_modes.join(', ')}, default: #{@options.duration_mode})"
|
142
|
+
) do |d|
|
143
|
+
@options.duration_mode = d
|
144
|
+
end
|
145
|
+
|
146
|
+
# Parse basic, common and specific options for receiver client
|
147
|
+
parse(args)
|
148
|
+
end # initialize(args)
|
149
|
+
|
150
|
+
end # class ReceiverOptionParser
|
151
|
+
|
152
|
+
end # module Options
|
153
|
+
|
154
|
+
# eof
|
@@ -0,0 +1,365 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2017 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require_relative 'sr_common_option_parser'
|
18
|
+
require_relative '../utils/string_utils'
|
19
|
+
|
20
|
+
module Options
|
21
|
+
|
22
|
+
# Option parser of basic (see Options::BasicOptionParser),
|
23
|
+
# common (see Options::SRCommonOptionParser)
|
24
|
+
# and specific options for sender client
|
25
|
+
# ==== Specific sender options
|
26
|
+
# count:: number of messages to send (default: DEFAULT_COUNT, see Defaults)
|
27
|
+
# msg-content:: message content (default: DEFAULT_MSG_CONTENT,
|
28
|
+
# see Defaults)
|
29
|
+
# msg-content-map-item:: message content map item
|
30
|
+
# msg-content-list-item:: message content list item
|
31
|
+
# msg-durable:: message durability (default: DEFAULT_MSG_DURABLE)
|
32
|
+
# msg-ttl:: message Time-To-Live (ms) (default: DEFAULT_MSG_TTL)
|
33
|
+
# msg-correlation-id:: message correlation ID
|
34
|
+
# msg-reply-to:: address to send reply to
|
35
|
+
# msg-group-id:: message group ID
|
36
|
+
# msg-to:: message destination
|
37
|
+
class SenderOptionParser < Options::SRCommonOptionParser
|
38
|
+
|
39
|
+
# Initialization and parsing of basic, common and specific sender options
|
40
|
+
# ==== Parameters
|
41
|
+
# args:: arguments to parse
|
42
|
+
def initialize(args)
|
43
|
+
# Initialization of basic and common options
|
44
|
+
super()
|
45
|
+
# Sender usage
|
46
|
+
@opt_parser.banner = "Usage: <sender_program> [OPTIONS]"
|
47
|
+
|
48
|
+
# Sender specific options with default values
|
49
|
+
|
50
|
+
# Number of messages option
|
51
|
+
@options.count = Defaults::DEFAULT_COUNT
|
52
|
+
# Message property option
|
53
|
+
@options.msg_properties = Defaults::DEFAULT_MSG_PROPERTIES
|
54
|
+
# Message content option
|
55
|
+
@options.msg_content = Defaults::DEFAULT_MSG_CONTENT
|
56
|
+
# Message content type option
|
57
|
+
@options.msg_content_type = Defaults::DEFAULT_MSG_CONTENT_TYPE
|
58
|
+
# Content type option
|
59
|
+
@options.content_type = Defaults::DEFAULT_CONTENT_TYPE
|
60
|
+
# Message durability
|
61
|
+
@options.msg_durable = Defaults::DEFAULT_MSG_DURABLE
|
62
|
+
# Message TTL
|
63
|
+
@options.msg_ttl = Defaults::DEFAULT_MSG_TTL
|
64
|
+
# Message correlation ID option
|
65
|
+
@options.msg_correlation_id = Defaults::DEFAULT_CORR_ID
|
66
|
+
# Address to send reply to
|
67
|
+
@options.msg_reply_to = Defaults::DEFAULT_MSG_REPLY_TO
|
68
|
+
# Message group ID option
|
69
|
+
@options.msg_group_id = Defaults::DEFAULT_GROUP_ID
|
70
|
+
# Message priority option
|
71
|
+
@options.msg_priority = Defaults::DEFAULT_MSG_PRIORITY
|
72
|
+
# Message ID option
|
73
|
+
@options.msg_id = Defaults::DEFAULT_MSG_ID
|
74
|
+
# Message user ID option
|
75
|
+
@options.msg_user_id = Defaults::DEFAULT_MSG_USER_ID
|
76
|
+
# Message subject option
|
77
|
+
@options.msg_subject = Defaults::DEFAULT_MSG_SUBJECT
|
78
|
+
# Anonymous producer option
|
79
|
+
@options.anonymous = Defaults::DEFAULT_ANONYMOUS
|
80
|
+
# Message destination
|
81
|
+
@options.msg_to = Defaults::DEFAULT_TO
|
82
|
+
|
83
|
+
# List of blocks executed at the end of parsing
|
84
|
+
# when all other options are already applied
|
85
|
+
@do_last = []
|
86
|
+
|
87
|
+
# Number of messages
|
88
|
+
@opt_parser.on(
|
89
|
+
"-c",
|
90
|
+
"--count COUNT",
|
91
|
+
Integer,
|
92
|
+
"number of messages to send (default: #{Defaults::DEFAULT_COUNT})"
|
93
|
+
) do |count|
|
94
|
+
@options.count = count
|
95
|
+
end
|
96
|
+
|
97
|
+
# Message content
|
98
|
+
@opt_parser.on(
|
99
|
+
"-m",
|
100
|
+
"--msg-content CONTENT",
|
101
|
+
String,
|
102
|
+
"message content (default: "+(
|
103
|
+
if Defaults::DEFAULT_MSG_CONTENT.nil?
|
104
|
+
"nil"
|
105
|
+
else
|
106
|
+
Defaults::DEFAULT_MSG_CONTENT
|
107
|
+
end
|
108
|
+
)+")"
|
109
|
+
) do |msg_content|
|
110
|
+
@do_last << Proc.new {
|
111
|
+
@options.msg_content = manual_cast(@options.content_type, msg_content)
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
# Message content from file
|
116
|
+
@opt_parser.on(
|
117
|
+
"--msg-content-from-file FILE",
|
118
|
+
String,
|
119
|
+
"message content from file"
|
120
|
+
) do |file|
|
121
|
+
@do_last << Proc.new {
|
122
|
+
@options.msg_content = manual_cast(@options.content_type, File.read(file))
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
# Message content type
|
127
|
+
@opt_parser.on(
|
128
|
+
"--msg-content-type TYPE",
|
129
|
+
String,
|
130
|
+
"AMQP message content type"
|
131
|
+
) do |msg_content_type|
|
132
|
+
@options.msg_content_type = msg_content_type
|
133
|
+
end
|
134
|
+
|
135
|
+
# Content type
|
136
|
+
@opt_parser.on(
|
137
|
+
"--content-type TYPE",
|
138
|
+
%w(string int long float bool),
|
139
|
+
"cast --msg-content, -list-item, and =values of -map-item" +
|
140
|
+
"and --msg-property to this type (default: #{Defaults::DEFAULT_CONTENT_TYPE})"
|
141
|
+
) do |content_type|
|
142
|
+
@options.content_type = content_type
|
143
|
+
end
|
144
|
+
|
145
|
+
# Message property
|
146
|
+
@opt_parser.on(
|
147
|
+
"-P",
|
148
|
+
"--msg-property KEY=VALUE",
|
149
|
+
String,
|
150
|
+
"property specified as KEY=VALUE (use '~' instead of '=' for auto-casting)"
|
151
|
+
) do |msg_property|
|
152
|
+
_ = parse_kv(msg_property) # ensure correct option format
|
153
|
+
@do_last << Proc.new {
|
154
|
+
if @options.msg_properties.nil?
|
155
|
+
@options.msg_properties = {}
|
156
|
+
end
|
157
|
+
|
158
|
+
key, value = parse_kv(msg_property)
|
159
|
+
@options.msg_properties[key] = value
|
160
|
+
}
|
161
|
+
end
|
162
|
+
# Message map content
|
163
|
+
@opt_parser.on(
|
164
|
+
"-M",
|
165
|
+
"--msg-content-map-item KEY=VALUE",
|
166
|
+
String,
|
167
|
+
"map item specified as KEY=VALUE (use '~' instead of '=' for auto-casting)"
|
168
|
+
) do |msg_content_map_item|
|
169
|
+
_ = parse_kv(msg_content_map_item) # ensure correct option format
|
170
|
+
@do_last << Proc.new {
|
171
|
+
if @options.msg_content.nil?
|
172
|
+
@options.msg_content = {}
|
173
|
+
end
|
174
|
+
|
175
|
+
key, value = parse_kv(msg_content_map_item)
|
176
|
+
@options.msg_content[key] = value
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
# Message list content
|
181
|
+
@opt_parser.on(
|
182
|
+
"-L",
|
183
|
+
"--msg-content-list-item VALUE",
|
184
|
+
"list item"
|
185
|
+
) do |msg_content_list_item|
|
186
|
+
@do_last << Proc.new {
|
187
|
+
if @options.msg_content.nil?
|
188
|
+
@options.msg_content = []
|
189
|
+
end
|
190
|
+
|
191
|
+
if msg_content_list_item.start_with? "~"
|
192
|
+
value = msg_content_list_item[1..-1]
|
193
|
+
@options.msg_content.push(auto_cast(value))
|
194
|
+
else
|
195
|
+
@options.msg_content.push(
|
196
|
+
manual_cast(@options.content_type, msg_content_list_item))
|
197
|
+
end
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
201
|
+
# Message durability
|
202
|
+
@opt_parser.on(
|
203
|
+
"--msg-durable DURABILITY",
|
204
|
+
BOOLEAN_STRINGS,
|
205
|
+
"message durability (yes/no|True/False|true/false, default: "+
|
206
|
+
"#{Defaults::DEFAULT_MSG_DURABLE})"
|
207
|
+
) do |msg_durable|
|
208
|
+
@options.msg_durable = StringUtils.str_to_bool(msg_durable)
|
209
|
+
end
|
210
|
+
|
211
|
+
# Message TTL
|
212
|
+
@opt_parser.on(
|
213
|
+
"--msg-ttl TTL",
|
214
|
+
Integer,
|
215
|
+
"message Time-To-Live (ms) (default: #{Defaults::DEFAULT_MSG_TTL})"
|
216
|
+
) do |msg_ttl|
|
217
|
+
@options.msg_ttl = msg_ttl
|
218
|
+
end
|
219
|
+
|
220
|
+
# Message correlation id
|
221
|
+
@opt_parser.on(
|
222
|
+
"--msg-correlation-id ID",
|
223
|
+
String,
|
224
|
+
"message correlation ID"
|
225
|
+
) do |msg_correlation_id|
|
226
|
+
@options.msg_correlation_id = msg_correlation_id
|
227
|
+
end
|
228
|
+
|
229
|
+
# Address to send reply to
|
230
|
+
@opt_parser.on(
|
231
|
+
"--msg-reply-to ADDRESS",
|
232
|
+
String,
|
233
|
+
"address to send reply to"
|
234
|
+
) do |msg_reply_to|
|
235
|
+
@options.msg_reply_to = msg_reply_to
|
236
|
+
end
|
237
|
+
|
238
|
+
# Message group id
|
239
|
+
@opt_parser.on(
|
240
|
+
"--msg-group-id ID",
|
241
|
+
String,
|
242
|
+
"message group ID"
|
243
|
+
) do |msg_group_id|
|
244
|
+
@options.msg_group_id = msg_group_id
|
245
|
+
end
|
246
|
+
|
247
|
+
# Message priority
|
248
|
+
@opt_parser.on(
|
249
|
+
"--msg-priority PRIORITY",
|
250
|
+
Integer,
|
251
|
+
"message priority"
|
252
|
+
) do |msg_priority|
|
253
|
+
@options.msg_priority = msg_priority
|
254
|
+
end
|
255
|
+
|
256
|
+
# Message ID
|
257
|
+
@opt_parser.on(
|
258
|
+
"--msg-id ID",
|
259
|
+
String,
|
260
|
+
"message ID"
|
261
|
+
) do |msg_id|
|
262
|
+
@options.msg_id = msg_id
|
263
|
+
end
|
264
|
+
|
265
|
+
# Message user ID
|
266
|
+
@opt_parser.on(
|
267
|
+
"--msg-user-id ID",
|
268
|
+
String,
|
269
|
+
"message user ID"
|
270
|
+
) do |msg_user_id|
|
271
|
+
@options.msg_user_id = msg_user_id
|
272
|
+
end
|
273
|
+
|
274
|
+
# Message subject
|
275
|
+
@opt_parser.on(
|
276
|
+
"--msg-subject SUBJECT",
|
277
|
+
String,
|
278
|
+
"message subject"
|
279
|
+
) do |msg_subject|
|
280
|
+
@options.msg_subject = msg_subject
|
281
|
+
end
|
282
|
+
|
283
|
+
# Anonymous producer
|
284
|
+
@opt_parser.on(
|
285
|
+
"--anonymous [ANONYMOUS]",
|
286
|
+
BOOLEAN_STRINGS,
|
287
|
+
"send message by connection level anonymous sender" +
|
288
|
+
" (default: #{Defaults::DEFAULT_ANONYMOUS})"
|
289
|
+
) do |anonymous|
|
290
|
+
@options.anonymous = true
|
291
|
+
@options.anonymous = StringUtils.str_to_bool(anonymous) if anonymous
|
292
|
+
end
|
293
|
+
|
294
|
+
# Duration mode
|
295
|
+
duration_modes = %w(before-send after-send after-send-tx-action)
|
296
|
+
@options.duration_mode = "before-send"
|
297
|
+
@opt_parser.on(
|
298
|
+
"--duration-mode MODE", duration_modes,
|
299
|
+
"in use with --duration defines where to wait (allowed: #{duration_modes.join(', ')}, default: #{@options.duration_mode})"
|
300
|
+
) do |d|
|
301
|
+
@options.duration_mode = d
|
302
|
+
end
|
303
|
+
|
304
|
+
# Destination
|
305
|
+
@opt_parser.on(
|
306
|
+
"--msg-to ADDRESS",
|
307
|
+
String,
|
308
|
+
"destination ADDRESS"
|
309
|
+
) do |msg_to|
|
310
|
+
@options.msg_to = msg_to
|
311
|
+
end
|
312
|
+
|
313
|
+
# Parse basic, common and specific options for sender client
|
314
|
+
parse(args)
|
315
|
+
# Apply options which need to be applied last
|
316
|
+
@do_last.each { |proc| proc.call }
|
317
|
+
end # initialize
|
318
|
+
|
319
|
+
private
|
320
|
+
def parse_kv(key_value)
|
321
|
+
if key_value.include? "="
|
322
|
+
key, value = key_value.split("=")
|
323
|
+
value = "" if value.nil?
|
324
|
+
return key, manual_cast(@options.content_type, value)
|
325
|
+
elsif key_value.include? "~"
|
326
|
+
key, value = key_value.split("~")
|
327
|
+
return key, auto_cast(value)
|
328
|
+
else
|
329
|
+
raise OptionParser::InvalidArgument, "kv pair '#{key_value}' is of invalid format, = or ~ required"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
private
|
334
|
+
def auto_cast(value)
|
335
|
+
if StringUtils.str_is_int?(value)
|
336
|
+
return value.to_i
|
337
|
+
elsif StringUtils.str_is_float?(value)
|
338
|
+
return value.to_f
|
339
|
+
elsif StringUtils.str_is_bool?(value)
|
340
|
+
return StringUtils.str_to_bool(value)
|
341
|
+
end
|
342
|
+
return value
|
343
|
+
end
|
344
|
+
|
345
|
+
private
|
346
|
+
def manual_cast(type, value)
|
347
|
+
case type
|
348
|
+
when "int"
|
349
|
+
return Integer(value)
|
350
|
+
when "float"
|
351
|
+
return Float(value)
|
352
|
+
when "long"
|
353
|
+
return Integer(value)
|
354
|
+
when "bool"
|
355
|
+
return StringUtils.str_to_bool(value)
|
356
|
+
else
|
357
|
+
return value
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
end # class SenderOptionParser
|
362
|
+
|
363
|
+
end # module Options
|
364
|
+
|
365
|
+
# eof
|