legion-transport 1.1.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop-analysis.yml +41 -0
- data/.github/workflows/sourcehawk-scan.yml +20 -0
- data/.gitignore +4 -2
- data/.rubocop.yml +7 -6
- data/CHANGELOG.md +2 -7
- data/CODE_OF_CONDUCT.md +75 -0
- data/CONTRIBUTING.md +55 -0
- data/Gemfile +7 -0
- data/INDIVIDUAL_CONTRIBUTOR_LICENSE.md +30 -0
- data/LICENSE +201 -0
- data/NOTICE.txt +9 -0
- data/README.md +90 -2
- data/SECURITY.md +9 -0
- data/attribution.txt +1 -0
- data/legion-transport.gemspec +23 -33
- data/lib/legion/transport.rb +25 -2
- data/lib/legion/transport/common.rb +3 -3
- data/lib/legion/transport/connection.rb +45 -18
- data/lib/legion/transport/connection/ssl.rb +35 -0
- data/lib/legion/transport/connection/vault.rb +9 -0
- data/lib/legion/transport/consumer.rb +0 -0
- data/lib/legion/transport/exchange.rb +15 -3
- data/lib/legion/transport/exchanges/crypt.rb +1 -1
- data/lib/legion/transport/exchanges/extensions.rb +11 -0
- data/lib/legion/transport/exchanges/lex.rb +1 -4
- data/lib/legion/transport/exchanges/node.rb +0 -0
- data/lib/legion/transport/exchanges/task.rb +0 -0
- data/lib/legion/transport/message.rb +53 -14
- data/lib/legion/transport/messages/check_subtask.rb +0 -0
- data/lib/legion/transport/messages/dynamic.rb +2 -1
- data/lib/legion/transport/messages/{node_health.rb → extension.rb} +4 -4
- data/lib/legion/transport/messages/lex_register.rb +3 -3
- data/lib/legion/transport/messages/request_cluster_secret.rb +0 -0
- data/lib/legion/transport/messages/subtask.rb +11 -0
- data/lib/legion/transport/messages/task.rb +41 -0
- data/lib/legion/transport/messages/task_log.rb +0 -0
- data/lib/legion/transport/messages/task_update.rb +7 -2
- data/lib/legion/transport/queue.rb +6 -6
- data/lib/legion/transport/queues/node.rb +0 -0
- data/lib/legion/transport/queues/node_crypt.rb +0 -0
- data/lib/legion/transport/queues/node_status.rb +0 -0
- data/lib/legion/transport/queues/task_log.rb +0 -0
- data/lib/legion/transport/queues/task_update.rb +0 -0
- data/lib/legion/transport/settings.rb +59 -35
- data/lib/legion/transport/version.rb +1 -1
- data/sonar-project.properties +1 -1
- data/sourcehawk.yml +4 -0
- metadata +44 -142
- data/.circleci/config.yml +0 -89
- data/.rspec +0 -1
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/bitbucket-pipelines.yml +0 -24
- data/settings/transport.json +0 -5
data/NOTICE.txt
ADDED
data/README.md
CHANGED
@@ -1,3 +1,91 @@
|
|
1
|
-
|
1
|
+
Legion::Transport
|
2
|
+
=====
|
2
3
|
|
3
|
-
|
4
|
+
Legion::Transport is the gem responsible for connecting LegionIO to the FIFO queue system(RabbitMQ over AMQP 0.9.1)
|
5
|
+
|
6
|
+
Supported Ruby versions and implementations
|
7
|
+
------------------------------------------------
|
8
|
+
|
9
|
+
Legion::Transport should work identically on:
|
10
|
+
|
11
|
+
* JRuby 9.2+
|
12
|
+
* Ruby 2.4+
|
13
|
+
|
14
|
+
|
15
|
+
Installation and Usage
|
16
|
+
------------------------
|
17
|
+
|
18
|
+
You can verify your installation using this piece of code:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
gem install legion-transport
|
22
|
+
```
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'legion/transport'
|
26
|
+
conn = Legion::Transport::Connection
|
27
|
+
conn.setup
|
28
|
+
conn.channel # => ::Bunny::Channel
|
29
|
+
conn.session # => ::Bunny::Session
|
30
|
+
```
|
31
|
+
|
32
|
+
Settings
|
33
|
+
----------
|
34
|
+
|
35
|
+
```json
|
36
|
+
{
|
37
|
+
"type": "rabbitmq",
|
38
|
+
"connected": false,
|
39
|
+
"logger_level": "info",
|
40
|
+
"messages": {
|
41
|
+
"encrypt": false,
|
42
|
+
"ttl": null,
|
43
|
+
"priority": 0,
|
44
|
+
"persistent": true
|
45
|
+
},
|
46
|
+
"prefetch": 2,
|
47
|
+
"exchanges": {
|
48
|
+
"type": "topic",
|
49
|
+
"arguments": {},
|
50
|
+
"auto_delete": false,
|
51
|
+
"durable": true,
|
52
|
+
"internal": false
|
53
|
+
},
|
54
|
+
"queues": {
|
55
|
+
"manual_ack": true,
|
56
|
+
"durable": true,
|
57
|
+
"exclusive": false,
|
58
|
+
"block": false,
|
59
|
+
"auto_delete": false,
|
60
|
+
"arguments": {
|
61
|
+
"x-max-priority": 255,
|
62
|
+
"x-overflow": "reject-publish"
|
63
|
+
}
|
64
|
+
},
|
65
|
+
"connection": {
|
66
|
+
"read_timeout": 1,
|
67
|
+
"heartbeat": 30,
|
68
|
+
"automatically_recover": true,
|
69
|
+
"continuation_timeout": 4000,
|
70
|
+
"network_recovery_interval": 1,
|
71
|
+
"connection_timeout": 1,
|
72
|
+
"frame_max": 65536,
|
73
|
+
"user": "guest",
|
74
|
+
"password": "guest",
|
75
|
+
"host": "127.0.0.1",
|
76
|
+
"port": "5672",
|
77
|
+
"vhost": "/",
|
78
|
+
"recovery_attempts": 100,
|
79
|
+
"logger_level": "info",
|
80
|
+
"connected": false
|
81
|
+
},
|
82
|
+
"channel": {
|
83
|
+
"default_worker_pool_size": 1,
|
84
|
+
"session_worker_pool_size": 8
|
85
|
+
}
|
86
|
+
}
|
87
|
+
```
|
88
|
+
Authors
|
89
|
+
----------
|
90
|
+
|
91
|
+
* [Matthew Iverson](https://github.com/Esity) - current maintainer
|
data/SECURITY.md
ADDED
data/attribution.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Add attributions here.
|
data/legion-transport.gemspec
CHANGED
@@ -1,43 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/legion/transport/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
6
|
+
spec.name = 'legion-transport'
|
7
7
|
spec.version = Legion::Transport::VERSION
|
8
8
|
spec.authors = ['Esity']
|
9
|
-
spec.email = [
|
10
|
-
|
11
|
-
spec.summary = 'Used by Legion to connect with RabbitMQ'
|
12
|
-
spec.description = 'The Legion transport gem'
|
13
|
-
spec.homepage = 'https://bitbucket.org/legion-io/legion-transport'
|
14
|
-
spec.required_ruby_version = '>= 2.5.0'
|
9
|
+
spec.email = %w[matthewdiverson@gmail.com ruby@optum.com]
|
15
10
|
|
11
|
+
spec.summary = 'Manages the connection to the transport tier(RabbitMQ)'
|
12
|
+
spec.description = 'The Gem to connect LegionIO and it\'s extensions to the transport tier'
|
13
|
+
spec.homepage = 'https://github.com/Optum/legion-transport'
|
14
|
+
spec.license = 'Apache-2.0'
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
spec.required_ruby_version = '>= 2.5'
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.test_files = spec.files.select { |p| p =~ %r{^test/.*_test.rb} }
|
19
|
+
spec.extra_rdoc_files = %w[README.md LICENSE CHANGELOG.md]
|
16
20
|
spec.metadata = {
|
17
|
-
'bug_tracker_uri' => 'https://
|
18
|
-
'changelog_uri' => 'https://
|
19
|
-
'
|
20
|
-
'
|
21
|
+
'bug_tracker_uri' => 'https://github.com/Optum/legion-transport/issues',
|
22
|
+
'changelog_uri' => 'https://github.com/Optum/legion-transport/src/main/CHANGELOG.md',
|
23
|
+
'documentation_uri' => 'https://github.com/Optum/legion-transport',
|
24
|
+
'homepage_uri' => 'https://github.com/Optum/LegionIO',
|
25
|
+
'source_code_uri' => 'https://github.com/Optum/legion-transport',
|
26
|
+
'wiki_uri' => 'https://github.com/Optum/legion-transport/wiki'
|
21
27
|
}
|
22
28
|
|
23
|
-
spec.
|
24
|
-
|
25
|
-
end
|
26
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
-
spec.require_paths = ['lib']
|
28
|
-
|
29
|
-
spec.add_development_dependency 'bundler'
|
30
|
-
spec.add_development_dependency 'codecov'
|
31
|
-
spec.add_development_dependency 'legion-logging'
|
32
|
-
spec.add_development_dependency 'legion-settings'
|
33
|
-
spec.add_development_dependency 'march_hare' if RUBY_ENGINE == 'jruby'
|
34
|
-
spec.add_development_dependency 'rake'
|
35
|
-
spec.add_development_dependency 'rspec'
|
36
|
-
spec.add_development_dependency 'rspec_junit_formatter'
|
37
|
-
spec.add_development_dependency 'rubocop'
|
38
|
-
spec.add_development_dependency 'simplecov'
|
39
|
-
|
40
|
-
spec.add_dependency 'bunny'
|
41
|
-
spec.add_dependency 'concurrent-ruby'
|
29
|
+
spec.add_dependency 'bunny', '>= 2.17.0'
|
30
|
+
spec.add_dependency 'concurrent-ruby', '>= 1.1.7'
|
42
31
|
spec.add_dependency 'legion-json'
|
32
|
+
spec.add_dependency 'legion-settings'
|
43
33
|
end
|
data/lib/legion/transport.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'legion/transport/version'
|
2
|
+
require 'legion/settings'
|
3
|
+
require 'legion/transport/settings'
|
3
4
|
|
4
5
|
module Legion
|
5
6
|
module Transport
|
@@ -12,6 +13,28 @@ module Legion
|
|
12
13
|
TYPE = 'bunny'.freeze
|
13
14
|
CONNECTOR = ::Bunny
|
14
15
|
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def logger
|
19
|
+
@logger unless @logger.nil?
|
20
|
+
|
21
|
+
if ::Legion.const_defined?('Logging')
|
22
|
+
@logger = ::Legion::Logging
|
23
|
+
else
|
24
|
+
require 'logger'
|
25
|
+
@logger = ::Logger.new($stdout)
|
26
|
+
@logger.level = Logger::ERROR
|
27
|
+
end
|
28
|
+
|
29
|
+
@logger
|
30
|
+
end
|
31
|
+
|
32
|
+
def settings
|
33
|
+
Legion::Settings[:transport] if Legion.const_defined? 'Settings'
|
34
|
+
|
35
|
+
Legion::Transport::Settings.default
|
36
|
+
end
|
37
|
+
end
|
15
38
|
end
|
16
39
|
|
17
40
|
require_relative 'transport/common'
|
@@ -52,14 +52,14 @@ module Legion
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def close!
|
55
|
-
Legion::
|
55
|
+
Legion::Transport.logger.error 'close! called'
|
56
56
|
false unless Legion::Transport::Connection.channel_open?
|
57
57
|
Legion::Transport::Connection.channel.close
|
58
58
|
end
|
59
59
|
|
60
60
|
def close
|
61
|
-
Legion::
|
62
|
-
Legion::
|
61
|
+
Legion::Transport.logger.error 'close called'
|
62
|
+
Legion::Transport.logger.warn 'close called, but method is called close!'
|
63
63
|
close!
|
64
64
|
end
|
65
65
|
|
@@ -4,51 +4,73 @@ module Legion
|
|
4
4
|
module Transport
|
5
5
|
module Connection
|
6
6
|
class << self
|
7
|
+
def settings
|
8
|
+
Legion::Settings[:transport]
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
clone
|
13
|
+
end
|
14
|
+
|
7
15
|
def connector
|
8
16
|
Legion::Transport::CONNECTOR
|
9
17
|
end
|
10
18
|
|
11
|
-
def
|
12
|
-
|
19
|
+
def reconnect(connection_name: 'Legion', **)
|
20
|
+
@session = nil
|
21
|
+
@channel_thread = Concurrent::ThreadLocalVar.new(nil)
|
22
|
+
setup(connection_name: connection_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup(connection_name: 'Legion', **) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
26
|
+
Legion::Transport.logger.info("Using transport connector: #{Legion::Transport::CONNECTOR}")
|
13
27
|
|
14
28
|
if @session.respond_to?(:value) && session.respond_to?(:closed?) && session.closed?
|
15
29
|
@channel_thread = Concurrent::ThreadLocalVar.new(nil)
|
16
30
|
elsif @session.respond_to?(:value) && session.respond_to?(:closed?) && session.open?
|
17
31
|
nil
|
18
32
|
elsif Legion::Transport::TYPE == 'march_hare'
|
19
|
-
@session ||= Concurrent::
|
20
|
-
MarchHare.connect(host:
|
21
|
-
vhost:
|
22
|
-
user:
|
23
|
-
password:
|
24
|
-
port:
|
33
|
+
@session ||= Concurrent::AtomicReference.new(
|
34
|
+
MarchHare.connect(host: settings[:connection][:host],
|
35
|
+
vhost: settings[:connection][:vhost],
|
36
|
+
user: settings[:connection][:user],
|
37
|
+
password: settings[:connection][:password],
|
38
|
+
port: settings[:connection][:port])
|
25
39
|
)
|
26
40
|
@channel_thread = Concurrent::ThreadLocalVar.new(nil)
|
27
41
|
session.start
|
28
|
-
session.create_channel.basic_qos(
|
42
|
+
session.create_channel.basic_qos(settings[:prefetch])
|
43
|
+
Legion::Settings[:transport][:connected] = true
|
29
44
|
else
|
30
|
-
@session ||= Concurrent::
|
45
|
+
@session ||= Concurrent::AtomicReference.new(
|
31
46
|
connector.new(
|
32
47
|
Legion::Settings[:transport][:connection],
|
33
|
-
|
48
|
+
connection_name: connection_name,
|
49
|
+
logger: Legion::Transport.logger,
|
34
50
|
log_level: :info
|
35
51
|
)
|
36
52
|
)
|
37
53
|
@channel_thread = Concurrent::ThreadLocalVar.new(nil)
|
38
54
|
session.start
|
39
|
-
session.create_channel
|
55
|
+
session.create_channel(nil, settings[:channel][:session_worker_pool_size])
|
56
|
+
.basic_qos(settings[:prefetch], true)
|
57
|
+
Legion::Settings[:transport][:connected] = true
|
40
58
|
end
|
41
59
|
|
42
60
|
if session.respond_to? :on_blocked
|
43
|
-
session.on_blocked { Legion::
|
61
|
+
session.on_blocked { Legion::Transport.logger.warn('Legion::Transport is being blocked by RabbitMQ!') }
|
44
62
|
end
|
45
63
|
|
46
64
|
if session.respond_to? :on_unblocked
|
47
|
-
session.on_unblocked
|
65
|
+
session.on_unblocked do
|
66
|
+
Legion::Transport.logger.info('Legion::Transport is no longer being blocked by RabbitMQ')
|
67
|
+
end
|
48
68
|
end
|
49
69
|
|
50
70
|
if session.respond_to? :after_recovery_completed
|
51
|
-
session.after_recovery_completed
|
71
|
+
session.after_recovery_completed do
|
72
|
+
Legion::Transport.logger.info('Legion::Transport has completed recovery')
|
73
|
+
end
|
52
74
|
end
|
53
75
|
|
54
76
|
true
|
@@ -57,11 +79,11 @@ module Legion
|
|
57
79
|
def channel # rubocop:disable Metrics/AbcSize
|
58
80
|
return @channel_thread.value if !@channel_thread.value.nil? && @channel_thread.value.open?
|
59
81
|
|
60
|
-
@channel_thread.value = session.create_channel
|
82
|
+
@channel_thread.value = session.create_channel(nil, settings[:channel][:default_worker_pool_size], false, 10)
|
61
83
|
if Legion::Transport::TYPE == 'march_hare'
|
62
|
-
@channel_thread.value.basic_qos(
|
84
|
+
@channel_thread.value.basic_qos(settings[:prefetch])
|
63
85
|
else
|
64
|
-
@channel_thread.value.prefetch(
|
86
|
+
@channel_thread.value.prefetch(settings[:prefetch])
|
65
87
|
end
|
66
88
|
@channel_thread.value
|
67
89
|
end
|
@@ -77,14 +99,19 @@ module Legion
|
|
77
99
|
|
78
100
|
def channel_open?
|
79
101
|
channel.open?
|
102
|
+
rescue StandardError
|
103
|
+
false
|
80
104
|
end
|
81
105
|
|
82
106
|
def session_open?
|
83
107
|
session.open?
|
108
|
+
rescue StandardError
|
109
|
+
false
|
84
110
|
end
|
85
111
|
|
86
112
|
def shutdown
|
87
113
|
session.close
|
114
|
+
@session = nil
|
88
115
|
end
|
89
116
|
end
|
90
117
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Legion
|
2
|
+
module Transport
|
3
|
+
module Connection
|
4
|
+
module SSL
|
5
|
+
def settings
|
6
|
+
Legion::Settings[:transport][:tls] || {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def use_vault_pki?
|
10
|
+
settings[:use_vault_pki] && Legion::Settings[:crypt][:vault][:connected]
|
11
|
+
end
|
12
|
+
|
13
|
+
def use_tls?
|
14
|
+
settings[:use_tls] || Legion::Settings[:transport][:port] == 5671
|
15
|
+
end
|
16
|
+
|
17
|
+
def tls_cert
|
18
|
+
settings[:tls_cert]
|
19
|
+
end
|
20
|
+
|
21
|
+
def tls_key
|
22
|
+
settings[:tls_key]
|
23
|
+
end
|
24
|
+
|
25
|
+
def ca_certs
|
26
|
+
settings[:ca_certs]
|
27
|
+
end
|
28
|
+
|
29
|
+
def verify_peer?
|
30
|
+
settings[:verify_peer] || false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
File without changes
|
@@ -22,24 +22,29 @@ module Legion
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def delete_exchange(exchange)
|
25
|
-
Legion::
|
25
|
+
Legion::Transport.logger.warn "Exchange:#{exchange} exists with wrong parameters, deleting and creating"
|
26
26
|
channel.exchange_delete(exchange)
|
27
27
|
end
|
28
28
|
|
29
29
|
def default_options
|
30
|
-
hash =
|
30
|
+
hash = Concurrent::Hash.new
|
31
31
|
hash[:durable] = true
|
32
32
|
hash[:auto_delete] = false
|
33
33
|
hash[:arguments] = {}
|
34
|
+
hash[:passive] = passive?
|
34
35
|
hash
|
35
36
|
end
|
36
37
|
|
38
|
+
def passive?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
37
42
|
def exchange_name
|
38
43
|
self.class.ancestors.first.to_s.split('::')[2].downcase
|
39
44
|
end
|
40
45
|
|
41
46
|
def exchange_options
|
42
|
-
|
47
|
+
Concurrent::Hash.new
|
43
48
|
end
|
44
49
|
|
45
50
|
def delete(options = {})
|
@@ -52,6 +57,13 @@ module Legion
|
|
52
57
|
def default_type
|
53
58
|
'topic'
|
54
59
|
end
|
60
|
+
|
61
|
+
def channel
|
62
|
+
@channel ||= Legion::Transport::Connection.channel
|
63
|
+
rescue ChannelLevelException => e
|
64
|
+
@channel = Legion::Transport::Connection.channel
|
65
|
+
raise e unless @channel.open?
|
66
|
+
end
|
55
67
|
end
|
56
68
|
end
|
57
69
|
end
|