legion-transport 1.2.4 → 1.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5df8a97c0a9116b6e6882820661a69e91708c578511526752fa69aca081c688e
4
- data.tar.gz: 3407435e75ef5ddae5a9dd5c68d8b3b755541b98345909edfb13dae0cfa6112f
3
+ metadata.gz: 271e42352b05b1bf2ef9df79f3bafd66259882ae7aa530a5ffb967e76894ced5
4
+ data.tar.gz: a9e9ebe1f78b3735bc04f5c1f25beab05f944c41047192804f4dd441f644de63
5
5
  SHA512:
6
- metadata.gz: a9869f1963d7c939cc2ecfa27a49b15f60c4fee20dce78818040e9813f4b81a31352704e99e152b390d8578e09ac462a0dd84903fba45599c3386e1707c2d7ff
7
- data.tar.gz: 950098bfa689097417cad4ee2fb4395b0e2b6793127d3ac04a654254038f7ff9afc3cc91663d01b19f206ea29d6c751ea65843b35b7416bda881047378c40333
6
+ metadata.gz: 6c98b0b0a671e56928dc6123f68372466965509302b9ce9764997f65484aecc5fac5094723aaf6c96e833f662095d62bef86440aa76355f02679bc726cb164bb
7
+ data.tar.gz: d4dcb7bb674e7a25fe70aedaa7f8c528140ff365341b9a7f29ddaa08e5df9f50d2bcd2d4fb1f043e648fefb11fecede5303bec976b05cf8e3ea2761cefa44f0c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Legion::Transport ChangeLog
2
2
 
3
+ ## [1.2.5] - 2026-03-20
4
+
5
+ ### Added
6
+ - `Settings.resolve_hosts` — merges `host:`, `hosts:`, `server:`, `servers:` into a unified deduped list with default AMQP port (5672) injected where missing
7
+ - `Settings::DEFAULT_AMQP_PORT` constant (5672)
8
+ - Multi-host RabbitMQ cluster failover via Bunny's native `hosts:` parameter when 2+ hosts configured
9
+ - Support for `server:` and `servers:` keys in transport settings (consistency with legion-cache)
10
+
11
+ ### Fixed
12
+ - Port default changed from string `"5672"` to integer `5672` — fixes SSL auto-detect comparison in `Connection::SSL.use_tls?` which compared against integer `5671`
13
+ - SSL port auto-detect now uses `.to_i` for robustness
14
+
3
15
  ## [1.2.4] - 2026-03-20
4
16
 
5
17
  ### Fixed
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Legion::Transport is the Ruby gem responsible for connecting LegionIO to its FIFO queue system (RabbitMQ over AMQP 0.9.1). It provides thread-safe connection management, exchange/queue abstractions, message publishing with optional encryption, and consumer wrappers.
4
4
 
5
- **Version**: 1.2.3
5
+ **Version**: 1.2.5
6
6
 
7
7
  ## Features
8
8
 
@@ -71,6 +71,25 @@ exchange = Legion::Transport::Exchanges::Task.new
71
71
  exchange.publish(payload, routing_key: 'task.my_runner.my_function')
72
72
  ```
73
73
 
74
+ ## Connection Configuration
75
+
76
+ ```json
77
+ {
78
+ "transport": {
79
+ "connection": {
80
+ "host": "rabbitmq1.example.com",
81
+ "servers": ["rabbitmq2.example.com", "rabbitmq3.example.com:5673"],
82
+ "port": 5672,
83
+ "user": "legion",
84
+ "password": "secret",
85
+ "vhost": "/"
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ Supported server keys: `host:` (string), `hosts:` (array), `server:` (string), `servers:` (array). All are merged and deduped. Port 5672 is injected where omitted. Multiple hosts enable Bunny's cluster failover.
92
+
74
93
  ## Configuration
75
94
 
76
95
  Configuration is managed through `legion-settings` with environment variable overrides:
@@ -13,7 +13,7 @@ module Legion
13
13
  end
14
14
 
15
15
  def use_tls?
16
- settings[:use_tls] || Legion::Settings[:transport][:port] == 5671
16
+ settings[:use_tls] || Legion::Settings[:transport][:connection][:port].to_i == 5671
17
17
  end
18
18
 
19
19
  def tls_cert
@@ -33,12 +33,7 @@ module Legion
33
33
  nil
34
34
  else
35
35
  @session ||= Concurrent::AtomicReference.new(
36
- connector.new(
37
- Legion::Settings[:transport][:connection],
38
- connection_name: connection_name,
39
- logger: Legion::Transport.logger,
40
- log_level: :warn
41
- )
36
+ connector.new(build_bunny_opts(connection_name: connection_name))
42
37
  )
43
38
  @channel_thread = Concurrent::ThreadLocalVar.new(nil)
44
39
  session.start
@@ -97,6 +92,27 @@ module Legion
97
92
  session.close
98
93
  @session = nil
99
94
  end
95
+
96
+ private
97
+
98
+ def build_bunny_opts(connection_name:)
99
+ conn_settings = Legion::Settings[:transport][:connection].dup
100
+ resolved = conn_settings.delete(:resolved_hosts) || []
101
+
102
+ opts = conn_settings.merge(
103
+ connection_name: connection_name,
104
+ logger: Legion::Transport.logger,
105
+ log_level: :warn
106
+ )
107
+
108
+ if resolved.length > 1
109
+ opts[:hosts] = resolved.map { |h| { host: h.split(':').first, port: h.split(':').last.to_i } }
110
+ opts.delete(:host)
111
+ opts.delete(:port)
112
+ end
113
+
114
+ opts
115
+ end
100
116
  end
101
117
  end
102
118
  end
@@ -6,6 +6,14 @@ module Legion
6
6
  module Transport
7
7
  module Settings
8
8
  def self.connection
9
+ host = ENV['transport.connection.host'] || '127.0.0.1'
10
+ port = (ENV['transport.connection.port'] || DEFAULT_AMQP_PORT).to_i
11
+
12
+ existing = defined?(Legion::Settings) ? (Legion::Settings[:transport][:connection] || {}) : {}
13
+ extra_server = existing[:server]
14
+ extra_servers = existing[:servers] || []
15
+ extra_hosts = existing[:hosts] || []
16
+
9
17
  {
10
18
  read_timeout: 1,
11
19
  heartbeat: 30,
@@ -16,15 +24,32 @@ module Legion
16
24
  frame_max: 65_536,
17
25
  user: ENV['transport.connection.user'] || 'guest',
18
26
  password: ENV['transport.connection.password'] || 'guest',
19
- host: ENV['transport.connection.host'] || '127.0.0.1',
20
- port: ENV['transport.connection.port'] || '5672',
27
+ host: host,
28
+ port: port,
21
29
  vhost: ENV['transport.connection.vhost'] || '/',
22
30
  recovery_attempts: 100,
23
31
  logger_level: ENV['transport.log_level'] || 'info',
24
- connected: false
32
+ connected: false,
33
+ resolved_hosts: resolve_hosts(
34
+ host: host, hosts: Array(extra_hosts),
35
+ server: extra_server, servers: Array(extra_servers),
36
+ port: port
37
+ )
25
38
  }.merge(grab_vault_creds)
26
39
  end
27
40
 
41
+ DEFAULT_AMQP_PORT = 5672
42
+
43
+ def self.resolve_hosts(host: nil, hosts: [], server: nil, servers: [], port: nil)
44
+ port ||= DEFAULT_AMQP_PORT
45
+
46
+ all = Array(hosts) + Array(servers) + Array(host) + Array(server)
47
+ all = ["127.0.0.1:#{port}"] if all.empty?
48
+
49
+ all.map! { |s| s.to_s.include?(':') ? s.to_s : "#{s}:#{port}" }
50
+ all.uniq
51
+ end
52
+
28
53
  def self.grab_vault_creds
29
54
  return {} unless Legion::Settings[:crypt][:vault][:connected]
30
55
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Legion
4
4
  module Transport
5
- VERSION = '1.2.4'
5
+ VERSION = '1.2.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity