cli-proton-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,96 @@
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 common
22
+ # options for sender and receiver client
23
+ # ==== Common sender and receiver options
24
+ # log-msgs:: format of message(s) log (none/body/dict,
25
+ # default: DEFAULT_LOG_MSGS, see Defaults)
26
+ class SRCommonOptionParser < Options::BasicOptionParser
27
+
28
+ # Initialization of basic and common sender and receiver options
29
+ def initialize()
30
+ # Initialization of basic options
31
+ super()
32
+ # SR usage
33
+ @opt_parser.banner = "Usage: <sr_program> [OPTIONS]"
34
+
35
+ # SR specific options with default values
36
+
37
+ # Format of message log option
38
+ @options.log_msgs = Defaults::DEFAULT_LOG_MSGS
39
+ # Hash message content
40
+ @options.msg_content_hashed = Defaults::DEFAULT_MSG_CONTENT_HASHED
41
+ # Auto settle off
42
+ @options.auto_settle_off = Defaults::DEFAULT_AUTO_SETTLE_OFF
43
+
44
+ # Format of message log
45
+ @opt_parser.on(
46
+ "--log-msgs FORMAT",
47
+ %w(none body dict interop),
48
+ "format of message(s) log (none/body/dict/interop, "+
49
+ "default: #{Defaults::DEFAULT_LOG_MSGS})"
50
+ ) do |log_msgs|
51
+ @options.log_msgs = log_msgs
52
+ end
53
+
54
+ # Message content hashed
55
+ @opt_parser.on(
56
+ "--msg-content-hashed [HASHED]",
57
+ Options::BOOLEAN_STRINGS,
58
+ "display SHA-1 hash of message content in logged messages (true/false) (default: #{Defaults::DEFAULT_MSG_CONTENT_HASHED})"
59
+ ) do |msg_content_hashed|
60
+ @options.msg_content_hashed = true
61
+ @options.msg_content_hashed = \
62
+ StringUtils.str_to_bool(msg_content_hashed) if msg_content_hashed
63
+ end
64
+
65
+ # Auto settle off
66
+ @opt_parser.on(
67
+ "--auto-settle-off [OFF]",
68
+ Options::BOOLEAN_STRINGS,
69
+ "disable auto settle mode (default: #{Defaults::DEFAULT_AUTO_SETTLE_OFF})"
70
+ ) do |auto_settle_off|
71
+ @options.auto_settle_off = true
72
+ @options.auto_settle_off = \
73
+ StringUtils.str_to_bool(auto_settle_off) if auto_settle_off
74
+ end
75
+
76
+ @options.duration = 0
77
+ @opt_parser.on(
78
+ "--duration DURATION", Float,
79
+ "message actions total duration (defines msg-rate together with count, default 0)"
80
+ ) do |d|
81
+ @options.duration = d
82
+ end
83
+ end # initialize
84
+
85
+ # Parsing of basic and common options for sender and receiver client
86
+ # ==== Parameters
87
+ # args:: arguments to parse
88
+ def parse(args)
89
+ @opt_parser.parse(args)
90
+ end # parse(args)
91
+
92
+ end # class SRCommonOptionParser
93
+
94
+ end # module Options
95
+
96
+ # eof
@@ -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 'qpid_proton'
18
+ require_relative 'options/receiver_option_parser'
19
+ require_relative 'handlers/receiver_handler'
20
+
21
+ # ReceiverClient parses arguments
22
+ # and runs receiver
23
+ class ReceiverClient
24
+
25
+ # Initialization of receiver client,
26
+ # parsing receiver client arguments
27
+ # and receiver client run
28
+ # ==== Parameters
29
+ # args:: receiver client arguments
30
+ def initialize(args)
31
+ # Parse arguments
32
+ receiver_options_parser = Options::ReceiverOptionParser.new(args)
33
+ # Create receiver handler
34
+ receiver_handler = Handlers::ReceiverHandler.new(
35
+ receiver_options_parser.options.broker,
36
+ receiver_options_parser.options.log_msgs,
37
+ receiver_options_parser.options.msg_content_hashed,
38
+ receiver_options_parser.options.count,
39
+ receiver_options_parser.options.prefetch,
40
+ receiver_options_parser.options.process_reply_to,
41
+ receiver_options_parser.options.browse,
42
+ receiver_options_parser.options.selector,
43
+ receiver_options_parser.options.sasl_mechs,
44
+ receiver_options_parser.options.idle_timeout,
45
+ receiver_options_parser.options.max_frame_size,
46
+ receiver_options_parser.options.sasl_enabled,
47
+ receiver_options_parser.options.log_lib,
48
+ receiver_options_parser.options.recv_listen,
49
+ receiver_options_parser.options.recv_listen_port,
50
+ receiver_options_parser.options.auto_settle_off,
51
+ receiver_options_parser.options.exit_timer,
52
+ receiver_options_parser.options.duration,
53
+ receiver_options_parser.options.duration_mode
54
+ )
55
+ # Run receiver client
56
+ Qpid::Proton::Container.new(receiver_handler).run
57
+ end
58
+
59
+ end # class ReceiverClient
60
+
61
+ # eof
@@ -0,0 +1,69 @@
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 'qpid_proton'
18
+ require_relative 'options/sender_option_parser'
19
+ require_relative 'handlers/sender_handler'
20
+
21
+ # SenderClient parses arguments
22
+ # and runs sender
23
+ class SenderClient
24
+
25
+ # Initialization of sender client,
26
+ # parsing sender client arguments
27
+ # and sender client run
28
+ # ==== Parameters
29
+ # args:: sender client arguments
30
+ def initialize(args)
31
+ # Parse arguments
32
+ sender_options_parser = Options::SenderOptionParser.new(args)
33
+ # Create sender handler
34
+ sender_handler = Handlers::SenderHandler.new(
35
+ sender_options_parser.options.broker,
36
+ sender_options_parser.options.log_msgs,
37
+ sender_options_parser.options.msg_content_hashed,
38
+ sender_options_parser.options.count,
39
+ sender_options_parser.options.msg_properties,
40
+ sender_options_parser.options.msg_content,
41
+ sender_options_parser.options.msg_content_type,
42
+ sender_options_parser.options.msg_durable,
43
+ sender_options_parser.options.msg_ttl,
44
+ sender_options_parser.options.msg_correlation_id,
45
+ sender_options_parser.options.msg_reply_to,
46
+ sender_options_parser.options.msg_group_id,
47
+ sender_options_parser.options.msg_to,
48
+ sender_options_parser.options.msg_priority,
49
+ sender_options_parser.options.msg_id,
50
+ sender_options_parser.options.msg_user_id,
51
+ sender_options_parser.options.msg_subject,
52
+ sender_options_parser.options.anonymous,
53
+ sender_options_parser.options.sasl_mechs,
54
+ sender_options_parser.options.idle_timeout,
55
+ sender_options_parser.options.max_frame_size,
56
+ sender_options_parser.options.sasl_enabled,
57
+ sender_options_parser.options.log_lib,
58
+ sender_options_parser.options.auto_settle_off,
59
+ sender_options_parser.options.exit_timer,
60
+ sender_options_parser.options.duration,
61
+ sender_options_parser.options.duration_mode
62
+ )
63
+ # Run sender client
64
+ Qpid::Proton::Container.new(sender_handler).run
65
+ end
66
+
67
+ end # class SenderClient
68
+
69
+ # eof
@@ -0,0 +1,44 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # Create a Duration at the start of the process and use it to sleep for delays
19
+ class Duration
20
+ # @param duration the total duration
21
+ # @param count the number of evenly-spaced delays within the duration
22
+ # @param mode only delay for this mode
23
+ def initialize(duration, count, mode)
24
+ @delay = count > 0 ? duration / count : 0 # Time for each delay
25
+ @deadline = Time.now + @delay # End time of next call to #delay
26
+ @mode = mode
27
+ end
28
+
29
+ attr_reader :mode
30
+
31
+ # Return nil if mode != self.mode.
32
+ # Return the next delay period, taking account of cumulative time taken so far.
33
+ # If block given, call with the delay period.
34
+ def delay(mode)
35
+ if mode == @mode
36
+ d = @deadline - Time.now
37
+ d = 0 if d < 0 # No negative delays
38
+ @deadline += @delay
39
+ block_given? ? yield(d) : d
40
+ end
41
+ end
42
+
43
+ def zero?() @delay.zero?; end
44
+ end
@@ -0,0 +1,39 @@
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
+ # Module containing environment utilities for cli-proton-ruby clients
18
+ module EnvUtils
19
+
20
+ # Function to set environment variable for client library logging
21
+ # ==== Parameters
22
+ # level:: log level to set and use
23
+ def self.set_log_lib_env(level)
24
+ case level
25
+ when "TRANSPORT_FRM"
26
+ ENV['PN_TRACE_FRM'] = "true"
27
+ when "TRANSPORT_RAW"
28
+ ENV['PN_TRACE_RAW'] = "true"
29
+ when "TRANSPORT_DRV"
30
+ ENV['PN_TRACE_DRV'] = "true"
31
+ when "NONE"
32
+ else
33
+ raise ArgumentError, "Invalid client library logging level: #{level}"
34
+ end
35
+ end
36
+
37
+ end # module EnvUtils
38
+
39
+ # eof
@@ -0,0 +1,44 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # Timer that exits the process if it expires.
19
+ # Use a timer thread, as the Qpid::Proton::Container does not yet provide scheduled tasks.
20
+
21
+ class ExitTimer
22
+
23
+ attr_reader :timeout
24
+
25
+ # Start the timer to exit after timeout.
26
+ def initialize(timeout)
27
+ @timeout = timeout
28
+ @lock = Mutex.new
29
+ reset
30
+ Thread.new do
31
+ while (delta = @lock.synchronize { @deadline - Time.now } ) > 0
32
+ sleep delta
33
+ end
34
+ puts "timeout expired"
35
+ exit(0)
36
+ end
37
+ end
38
+
39
+ # Reset the timer to count to timeout from now
40
+ def reset()
41
+ @lock.synchronize { @deadline = Time.now + @timeout }
42
+ end
43
+
44
+ end
@@ -0,0 +1,81 @@
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 'digest'
18
+
19
+ # Module containing string utilities for cli-proton-ruby clients
20
+ module StringUtils
21
+
22
+ # Function to check if string variable is convertible to integer
23
+ # ==== Parameters
24
+ # value:: string variable to convert
25
+ # ==== Returns
26
+ # true if string variable is convertible to integer, false otherwise
27
+ def self.str_is_int?(value)
28
+ !Integer(value).nil? rescue false
29
+ end
30
+
31
+ # Function to check if string variable is convertible to float
32
+ # ==== Parameters
33
+ # value:: string variable to convert
34
+ # ==== Returns
35
+ # true if string variable is convertible to float, false otherwise
36
+ def self.str_is_float?(value)
37
+ !Float(value).nil? rescue false
38
+ end
39
+
40
+ # Function to check if string variable is convertible to client bool value
41
+ # ==== Returns
42
+ # true if string variable is convertible to client bool value, false otherwise
43
+ def self.str_is_bool?(value)
44
+ begin
45
+ str_to_bool value
46
+ rescue ArgumentError
47
+ return false
48
+ end
49
+
50
+ return true
51
+ end
52
+
53
+ # Function to convert string variable to client bool value
54
+ # (yes/no|True/False|true/false)
55
+ # ==== Parameters
56
+ # value:: string variable to convert
57
+ # ==== Returns
58
+ # bool value of the variable
59
+ # ==== Raises
60
+ # ArgumentError for invalid argument
61
+ def self.str_to_bool(value)
62
+ # If positive value
63
+ if ["yes", "True", "true"].include?(value)
64
+ # Return true
65
+ return true
66
+ # If negative value
67
+ elsif ["no", "False", "false"].include?(value)
68
+ # Return false
69
+ return false
70
+ end
71
+ # If value is not convertible, raise ArgumentError
72
+ raise ArgumentError, "invalid value for Boolean(): \"#{value}\""
73
+ end
74
+
75
+ def self.sha1_hash(value)
76
+ Digest::SHA1.hexdigest value.to_s
77
+ end
78
+
79
+ end # module StringUtils
80
+
81
+ # eof
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cli-proton-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Radim Kubis
8
+ - Jiri Danek
9
+ - Alan Conway
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2019-01-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: qpid_proton
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.26'
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.26.0
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "~>"
30
+ - !ruby/object:Gem::Version
31
+ version: '0.26'
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.26.0
35
+ description: cli-proton-ruby is a collection of commandline messaging clients suitable
36
+ for interacting with Message Oriented Middleware.
37
+ email: rkubis@redhat.com
38
+ executables:
39
+ - cli-proton-ruby-connector
40
+ - cli-proton-ruby-receiver
41
+ - cli-proton-ruby-sender
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - bin/cli-proton-ruby-connector
46
+ - bin/cli-proton-ruby-receiver
47
+ - bin/cli-proton-ruby-sender
48
+ - lib/connector_client.rb
49
+ - lib/constants.rb
50
+ - lib/defaults.rb
51
+ - lib/formatters.rb
52
+ - lib/formatters/basic_formatter.rb
53
+ - lib/formatters/dict_formatter.rb
54
+ - lib/formatters/interop_formatter.rb
55
+ - lib/handlers.rb
56
+ - lib/handlers/basic_handler.rb
57
+ - lib/handlers/connector_handler.rb
58
+ - lib/handlers/receiver_handler.rb
59
+ - lib/handlers/sender_handler.rb
60
+ - lib/handlers/sr_common_handler.rb
61
+ - lib/options.rb
62
+ - lib/options/basic_option_parser.rb
63
+ - lib/options/connector_option_parser.rb
64
+ - lib/options/receiver_option_parser.rb
65
+ - lib/options/sender_option_parser.rb
66
+ - lib/options/sr_common_option_parser.rb
67
+ - lib/receiver_client.rb
68
+ - lib/sender_client.rb
69
+ - lib/utils/duration.rb
70
+ - lib/utils/env_utils.rb
71
+ - lib/utils/exit_timer.rb
72
+ - lib/utils/string_utils.rb
73
+ homepage: http://rubygems.org/gems/cli-proton-ruby
74
+ licenses:
75
+ - Apache-2.0
76
+ metadata:
77
+ source_code_uri: https://github.com/rh-messaging/cli-proton-ruby
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 2.0.0p648
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.7.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Qpid Proton Ruby commandline clients
98
+ test_files: []