legion-transport 0.1.0 → 1.0.0

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +12 -12
  3. data/.idea/.rakeTasks +7 -0
  4. data/.idea/legion-transport.iml +45 -0
  5. data/.idea/misc.xml +7 -0
  6. data/.idea/modules.xml +8 -0
  7. data/.idea/vagrant.xml +7 -0
  8. data/.idea/workspace.xml +14 -0
  9. data/.rspec +1 -0
  10. data/.rubocop.yml +1 -8
  11. data/CHANGELOG.md +0 -0
  12. data/Gemfile +0 -1
  13. data/README.md +35 -0
  14. data/legion-transport.gemspec +15 -5
  15. data/lib/legion/transport.rb +11 -9
  16. data/lib/legion/transport/common.rb +23 -18
  17. data/lib/legion/transport/connection.rb +55 -12
  18. data/lib/legion/transport/consumer.rb +7 -1
  19. data/lib/legion/transport/exchange.rb +44 -6
  20. data/lib/legion/transport/exchanges/crypt.rb +11 -0
  21. data/lib/legion/transport/exchanges/node.rb +11 -0
  22. data/lib/legion/transport/message.rb +94 -2
  23. data/lib/legion/transport/messages/check_subtask.rb +25 -0
  24. data/lib/legion/transport/messages/dynamic.rb +24 -0
  25. data/lib/legion/transport/messages/lex_register.rb +11 -19
  26. data/lib/legion/transport/messages/node_health.rb +21 -0
  27. data/lib/legion/transport/messages/request_cluster_secret.rb +32 -0
  28. data/lib/legion/transport/messages/subtask.rb +38 -0
  29. data/lib/legion/transport/messages/task_log.rb +36 -0
  30. data/lib/legion/transport/messages/task_update.rb +3 -23
  31. data/lib/legion/transport/queue.rb +63 -6
  32. data/lib/legion/transport/queues/node.rb +15 -0
  33. data/lib/legion/transport/queues/node_status.rb +1 -1
  34. data/lib/legion/transport/queues/task_log.rb +1 -1
  35. data/lib/legion/transport/queues/task_update.rb +1 -1
  36. data/lib/legion/transport/settings.rb +64 -0
  37. data/lib/legion/transport/version.rb +1 -1
  38. data/settings/transport.json +9 -1
  39. metadata +81 -33
  40. data/lib/legion/transport/connections/bunny.rb +0 -53
  41. data/lib/legion/transport/connections/common.rb +0 -36
  42. data/lib/legion/transport/connections/marchhare.rb +0 -20
  43. data/lib/legion/transport/consumers/bunny.rb +0 -11
  44. data/lib/legion/transport/consumers/common.rb +0 -8
  45. data/lib/legion/transport/consumers/marchhare.rb +0 -11
  46. data/lib/legion/transport/exchanges/bunny.rb +0 -28
  47. data/lib/legion/transport/exchanges/common.rb +0 -32
  48. data/lib/legion/transport/exchanges/marchhare.rb +0 -17
  49. data/lib/legion/transport/messages/base.rb +0 -22
  50. data/lib/legion/transport/messages/node_status.rb +0 -49
  51. data/lib/legion/transport/messages/task_check_subtask.rb +0 -35
  52. data/lib/legion/transport/messages/task_subtask.rb +0 -45
  53. data/lib/legion/transport/queues/bunny.rb +0 -26
  54. data/lib/legion/transport/queues/common.rb +0 -45
  55. data/lib/legion/transport/queues/marchhare.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8e533b2973535c4763ab30eddf935de8f180e1114dc94c04ca8b1f875ff29ac
4
- data.tar.gz: 595f0dbb65675f616c9485f28433220475ded71a4727e8f3db8f4fc8206449c3
3
+ metadata.gz: 4b8ebe4ac7e742ce233b6a34093a8b98d9edae6fd93a15bc1f0de46aedd0ae03
4
+ data.tar.gz: 24574a28c192e3f79da7b36b33e19de1b93550162f58ecdd0df136892a7aee1d
5
5
  SHA512:
6
- metadata.gz: 6b1eac97b2775e5d67ff1f27efecf93fa96ab7dc276a5698a1323be276ee0176040eccec771752eee49068a928cce8fa044cb9ddb0d59c603f37c511c913937e
7
- data.tar.gz: 4efa70d6438d27bfb9a9ceda17be7bb63f3f34aca5ff0dfad33186f3d16d70d99fc4aeeeecc227769a098a0118554abca4781ec5c8b37de8f359f928b52e9b25
6
+ metadata.gz: 4b956aeca717ed356ea934f07f2a3ec58ae30da3d5b3aa3fe39b6e2968cda9f0ee42843751abefa120942c4ffd2df7f4f53bdd8cb5bb51c05e91ac65200d4299
7
+ data.tar.gz: 6165b84e313abce9a15e7126e6cae813323bc3ac4969bf8c7aba2e72c6e201e8d864e47d9125dfe8c216f78a50a728f7898634de20fd2967e532c7955637d4da
@@ -11,7 +11,7 @@ jobs:
11
11
  command: rubocop
12
12
  - store_test_results:
13
13
  path: test_results
14
- "ruby-2.3":
14
+ "ruby-two-three":
15
15
  docker:
16
16
  - image: circleci/ruby:2.3
17
17
  - image: rabbitmq:3.7
@@ -27,7 +27,7 @@ jobs:
27
27
  - store_test_results:
28
28
  path: test-results
29
29
 
30
- "ruby-2.4":
30
+ "ruby-two-four":
31
31
  docker:
32
32
  - image: circleci/ruby:2.4-node
33
33
  - image: rabbitmq:3.7
@@ -42,7 +42,7 @@ jobs:
42
42
  when: always
43
43
  - store_test_results:
44
44
  path: test-results
45
- "ruby-2.5":
45
+ "ruby-two-five":
46
46
  docker:
47
47
  - image: circleci/ruby:2.5-node
48
48
  - image: rabbitmq:3.7
@@ -57,7 +57,7 @@ jobs:
57
57
  when: always
58
58
  - store_test_results:
59
59
  path: test-results
60
- "ruby-2.6":
60
+ "ruby-two-six":
61
61
  docker:
62
62
  - image: circleci/ruby:2.6-node
63
63
  - image: rabbitmq:3.7
@@ -72,7 +72,7 @@ jobs:
72
72
  when: always
73
73
  - store_test_results:
74
74
  path: test-results
75
- "jruby-9.2":
75
+ "jruby-nine-two":
76
76
  docker:
77
77
  - image: circleci/jruby:9.2
78
78
  - image: rabbitmq:3.7
@@ -93,24 +93,24 @@ workflows:
93
93
  cop_rake_deploy:
94
94
  jobs:
95
95
  - rubocop
96
- - ruby-2.3:
96
+ - ruby-two-three:
97
97
  requires:
98
- - ruby-2.4
98
+ - ruby-two-four
99
99
  filters:
100
100
  branches:
101
101
  only: /\bdevelop\b|\bmaster\b/
102
- - ruby-2.4:
102
+ - ruby-two-four:
103
103
  requires:
104
104
  - rubocop
105
- - ruby-2.5:
105
+ - ruby-two-five:
106
106
  requires:
107
- - ruby-2.4
107
+ - ruby-two-four
108
108
  filters:
109
109
  branches:
110
110
  only: /\bdevelop\b|\bmaster\b/
111
- - ruby-2.6:
111
+ - ruby-two-six:
112
112
  requires:
113
- - ruby-2.4
113
+ - ruby-two-four
114
114
  filters:
115
115
  branches:
116
116
  only: /\bdevelop\b|\bmaster\b/
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build legion-transport-0.1.1.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install legion-transport-0.1.1.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install legion-transport-0.1.1.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.1 and build and push legion-transport-0.1.1.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
@@ -0,0 +1,45 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
9
+ </content>
10
+ <orderEntry type="inheritedJdk" />
11
+ <orderEntry type="sourceFolder" forTests="false" />
12
+ <orderEntry type="library" scope="PROVIDED" name="amq-protocol (v2.3.0, RVM: ruby-2.6.3) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.0, RVM: ruby-2.6.3) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.6.3) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="bunny (v2.14.4, RVM: ruby-2.6.3) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="codecov (v0.1.16, RVM: ruby-2.6.3) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.6, RVM: ruby-2.6.3) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby-ext (v1.1.6, RVM: ruby-2.6.3) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, RVM: ruby-2.6.3) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="docile (v1.3.2, RVM: ruby-2.6.3) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="jaro_winkler (v1.5.4, RVM: ruby-2.6.3) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.3.0, RVM: ruby-2.6.3) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="legion-json (v0.1.6, RVM: ruby-2.6.3) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="legion-logging (v1.0.0, RVM: ruby-2.6.3) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="legion-settings (v1.0.0, RVM: ruby-2.6.3) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="oj (v3.10.5, RVM: ruby-2.6.3) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.19.1, RVM: ruby-2.6.3) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="parser (v2.7.0.4, RVM: ruby-2.6.3) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, RVM: ruby-2.6.3) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, RVM: ruby-2.6.3) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.4, RVM: ruby-2.6.3) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.9.0, RVM: ruby-2.6.3) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.9.1, RVM: ruby-2.6.3) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.9.0, RVM: ruby-2.6.3) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.9.1, RVM: ruby-2.6.3) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.9.2, RVM: ruby-2.6.3) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="rspec_junit_formatter (v0.4.1, RVM: ruby-2.6.3) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v0.80.1, RVM: ruby-2.6.3) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.10.1, RVM: ruby-2.6.3) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.18.5, RVM: ruby-2.6.3) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.2, RVM: ruby-2.6.3) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v1.6.1, RVM: ruby-2.6.3) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="url (v0.3.2, RVM: ruby-2.6.3) [gem]" level="application" />
44
+ </component>
45
+ </module>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.6.3" project-jdk-type="RUBY_SDK" />
7
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/legion-transport.iml" filepath="$PROJECT_DIR$/.idea/legion-transport.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VagrantProjectSettings">
4
+ <option name="instanceFolder" value="" />
5
+ <option name="provider" value="" />
6
+ </component>
7
+ </project>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="CoverageOptionsProvider">
4
+ <option name="myAddOrReplace" value="0" />
5
+ </component>
6
+ <component name="Git.Settings">
7
+ <option name="PUSH_AUTO_UPDATE" value="true" />
8
+ <option name="ROOT_SYNC" value="DONT_SYNC" />
9
+ </component>
10
+ <component name="ProjectId" id="1Yl3FmIkCYycmcT2pLSMAlN1Wxa" />
11
+ <component name="PropertiesComponent">
12
+ <property name="settings.editor.selected.configurable" value="reference.settingsdialog.project.vagrant" />
13
+ </component>
14
+ </project>
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -6,21 +6,14 @@ Metrics/ClassLength:
6
6
  Max: 1500
7
7
  Metrics/BlockLength:
8
8
  Max: 50
9
- Exclude:
10
- - 'spec/legion/connections/*'
11
9
  Layout/SpaceAroundEqualsInParameterDefault:
12
10
  EnforcedStyle: space
13
11
  Style/SymbolArray:
14
12
  Enabled: true
15
- Layout/AlignHash:
16
- EnforcedHashRocketStyle: table
17
- EnforcedColonStyle: table
18
- Style/HashSyntax:
19
- EnforcedStyle: ruby19_no_mixed_keys
20
13
  Style/Documentation:
21
14
  Enabled: false
22
15
  AllCops:
23
- TargetRubyVersion: 2.4
16
+ TargetRubyVersion: 2.5
24
17
  Style/FrozenStringLiteralComment:
25
18
  Enabled: false
26
19
  Naming/FileName:
File without changes
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in legion-transport.gemspec
4
3
  gemspec
@@ -0,0 +1,35 @@
1
+ # Legion::Transport
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/legion/transport`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'legion-transport'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install legion-transport
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/legion-transport.
@@ -12,27 +12,37 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'The Legion transport gem'
13
13
  spec.homepage = 'https://bitbucket.org/legion-io/legion-transport'
14
14
 
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ spec.metadata = {
16
+ 'bug_tracker_uri' => 'https://legionio.atlassian.net/projects/TRANSPORT/issues',
17
+ 'changelog_uri' => 'https://bitbucket.org/legion-io/legion-transport/src/master/CHANGELOG.md',
18
+ 'homepage_uri' => 'https://bitbucket.org/legion-io/legion-transport',
19
+ 'wiki_uri' => 'https://bitbucket.org/legion-io/legion-transport/wiki/Home'
20
+ }
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
23
  f.match(%r{^(test|spec|features)/})
17
24
  end
18
25
  spec.bindir = 'exe'
19
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
27
  spec.require_paths = ['lib']
21
28
 
22
- spec.add_development_dependency 'bundler', '~> 1'
29
+ spec.add_development_dependency 'bundler'
23
30
  spec.add_development_dependency 'codecov'
24
31
  spec.add_development_dependency 'rake', '~> 10.0'
25
32
  spec.add_development_dependency 'rspec', '~> 3.0'
26
33
  spec.add_development_dependency 'rspec_junit_formatter'
27
34
  spec.add_development_dependency 'rubocop'
35
+ spec.add_development_dependency 'simplecov'
36
+ spec.add_dependency 'concurrent-ruby'
37
+ spec.add_dependency 'concurrent-ruby-ext'
28
38
 
29
39
  if RUBY_ENGINE == 'jruby'
30
- spec.add_development_dependency 'legion-settings-java', '~> 0.1'
40
+ spec.add_development_dependency 'legion-settings-java'
31
41
  spec.add_dependency 'march_hare'
32
42
  else
33
- spec.add_development_dependency 'legion-settings', '~> 0.1'
43
+ spec.add_development_dependency 'legion-settings'
34
44
  spec.add_dependency 'bunny'
35
45
  end
36
46
 
37
- spec.add_development_dependency 'legion-logging', '~> 0.1'
47
+ spec.add_development_dependency 'legion-logging'
38
48
  end
@@ -1,20 +1,22 @@
1
- require 'legion/transport/version'
1
+ require_relative 'transport/version'
2
+ require_relative 'transport/settings'
2
3
 
3
4
  module Legion
4
- # Base Legion::Transport
5
5
  module Transport
6
6
  if RUBY_ENGINE == 'jruby'
7
7
  require 'marchhare'
8
- CONNECTOR = 'marchhare'.freeze
8
+ TYPE = 'marchhare'.freeze
9
+ CONNECTOR = ::Marchhare
9
10
  else
10
11
  require 'bunny'
11
- CONNECTOR = 'bunny'.freeze
12
+ TYPE = 'bunny'.freeze
13
+ CONNECTOR = ::Bunny
12
14
  end
13
15
  end
14
16
 
15
- require 'legion/transport/common'
16
- require 'legion/transport/queue'
17
- require 'legion/transport/exchange'
18
- require 'legion/transport/consumer'
19
- require 'legion/transport/message'
17
+ require_relative 'transport/common'
18
+ require_relative 'transport/queue'
19
+ require_relative 'transport/exchange'
20
+ require_relative 'transport/consumer'
21
+ require_relative 'transport/message'
20
22
  end
@@ -3,16 +3,12 @@ require 'legion/transport/connection'
3
3
  module Legion
4
4
  module Transport
5
5
  module Common
6
- def open_channel(options = {})
7
- @channel = Legion::Transport::Connection.new(options).channel
6
+ def open_channel(_options = {})
7
+ @channel = Legion::Transport::Connection.channel
8
8
  end
9
9
 
10
- def channel_valid?(channel = @channel)
11
- return false if channel.nil?
12
- return false unless channel.instance_of?(::Bunny::Channel)
13
- return false if channel.closed?
14
-
15
- true
10
+ def channel_open?
11
+ channel.open?
16
12
  end
17
13
 
18
14
  def options_builder(first, *args)
@@ -51,20 +47,29 @@ module Legion
51
47
  end
52
48
  # rubocop:enable all
53
49
 
54
- def closed?
55
- @channel.closed?
50
+ def channel
51
+ @channel ||= Legion::Transport::Connection.channel
52
+ end
53
+
54
+ def close!
55
+ Legion::Logging.error 'close! called'
56
+ false unless Legion::Transport::Connection.channel_open?
57
+ Legion::Transport::Connection.channel.close
56
58
  end
57
59
 
58
- def channel(options = @options || {})
59
- @channel if channel_valid?
60
- @channel = options[:channel] if channel_valid?(options[:channel])
61
- @channel = open_channel(options) unless channel_valid?(@channel)
62
- @channel
60
+ def close
61
+ Legion::Logging.error 'close called'
62
+ Legion::Logging.warn 'close called, but method is called close!'
63
+ close!
63
64
  end
64
65
 
65
- def close(_options = @options || {})
66
- false if @channel.closed?
67
- @channel.close
66
+ def generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id)
67
+ tag = "#{Legion::Settings[:client][:name]}_"
68
+ tag.concat("#{lex_name}_") unless lex_name.nil?
69
+ tag.concat("#{runner_name}_") unless runner_name.nil?
70
+ tag.concat("#{thread}_")
71
+ tag.concat(SecureRandom.hex)
72
+ tag
68
73
  end
69
74
  end
70
75
  end
@@ -1,17 +1,60 @@
1
+ require 'concurrent-ruby'
2
+
1
3
  module Legion
2
4
  module Transport
3
- class Connection
4
- @@session = nil # rubocop:disable Style/ClassVars
5
- attr_accessor :session, :channel
6
-
7
- if RUBY_ENGINE == 'jruby'
8
- require 'march-hare'
9
- require 'legion/transport/connections/marchhare'
10
- include Legion::Transport::Connections::Marchhare
11
- else
12
- require 'bunny'
13
- require 'legion/transport/connections/bunny'
14
- include Legion::Transport::Connections::Bunny
5
+ module Connection
6
+ class << self
7
+ def connector
8
+ Legion::Transport::CONNECTOR
9
+ end
10
+
11
+ def setup
12
+ if @session.respond_to?(:value) && session.respond_to?(:closed?) && session.closed?
13
+ @channel_thread = Concurrent::ThreadLocalVar.new
14
+ elsif @session.respond_to?(:value) && session.respond_to?(:closed?) && session.open?
15
+ return nil
16
+ else
17
+ @session ||= Concurrent::Atom.new(
18
+ connector.new(
19
+ Legion::Settings[:transport][:connection],
20
+ logger: Legion::Logging::Logger.new(level: 'warn'), log_level: :info
21
+ )
22
+ )
23
+ @channel_thread = Concurrent::ThreadLocalVar.new
24
+ end
25
+
26
+ session.start
27
+ session.create_channel.basic_qos(1, true)
28
+ end
29
+
30
+ def channel
31
+ return @channel_thread.value if !@channel_thread.value.nil? && @channel_thread.value.open?
32
+
33
+ @channel_thread.value = session.create_channel
34
+ @channel_thread.value.prefetch(Legion::Settings[:transport][:prefetch])
35
+ @channel_thread.value
36
+ end
37
+
38
+ def session
39
+ nil if @session.nil?
40
+ @session.value
41
+ end
42
+
43
+ def channel_thread
44
+ channel
45
+ end
46
+
47
+ def channel_open?
48
+ channel.open?
49
+ end
50
+
51
+ def session_open?
52
+ session.open?
53
+ end
54
+
55
+ def shutdown
56
+ session.close
57
+ end
15
58
  end
16
59
  end
17
60
  end