surfliner-metadata_consumer 0.1.0.pre.alpha.5 → 0.1.0.pre.alpha.6
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 +4 -4
- data/CHANGES.md +12 -0
- data/Gemfile.lock +23 -23
- data/README.md +7 -6
- data/lib/surfliner/metadata_consumer/version.rb +1 -1
- data/lib/surfliner/mq/connection.rb +35 -27
- data/lib/surfliner/mq/connection_config.rb +30 -9
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25566009d8ccce03904d9020a0340511bbeb2fac08b5151c65705cd2d6117096
|
4
|
+
data.tar.gz: 24136a3ca25672bf7fcc8670ea61f11a34c547b515022f92e46b440fe1d315cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fef5c2196922e8f5476422ffd83400bc17edc957b0822a323628dd9cd525440e231e1d7402b761c71894806282c2ad11c8c450eb6dc37a6a6e99dac7d3adc9c5
|
7
|
+
data.tar.gz: 5014bdadb04910ca9888d8fe445342641462e33f6ec445333c4502dd322e428df5c5ecd01710018d7f905e80a889ce84815f7ff59b1d3908c00b405d5f02c048
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# 0.1.0.pre.alpha.6 (2025-04-25)
|
2
|
+
|
3
|
+
- Update to Bunny 2.24
|
4
|
+
- Allow `Mq::Connection#connect` to take a block, in which case the method
|
5
|
+
yields the open connection, closing the connection and channel afterwards.
|
6
|
+
- Add an option `await_response_on_close` to `Mq::ConnectionConfig`, defaulting
|
7
|
+
to true, to indicate whether the RabbitMQ client should wait for a response
|
8
|
+
when closing a session, along with a corresponding environment variable
|
9
|
+
`RABBITMQ_AWAIT_ON_CLOSE`
|
10
|
+
- Allows passing additional options to `Mq:ConnectionConfig#initialize` and
|
11
|
+
`#from_env`, which will then be passed to `Bunny::Session#initialize`
|
12
|
+
|
1
13
|
# 0.1.0.pre.alpha.5 (2025-03-25)
|
2
14
|
|
3
15
|
In order to support using one connection (and one underlying `Bunny::Session`)
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
surfliner-metadata_consumer (0.1.0.pre.alpha.
|
5
|
-
bunny (~> 2.
|
4
|
+
surfliner-metadata_consumer (0.1.0.pre.alpha.6)
|
5
|
+
bunny (~> 2.24)
|
6
6
|
opentelemetry-exporter-otlp (~> 0.26.3)
|
7
7
|
opentelemetry-instrumentation-all (~> 0.60.0)
|
8
8
|
opentelemetry-sdk (~> 1.4.1)
|
@@ -37,26 +37,26 @@ GEM
|
|
37
37
|
diff-lcs (1.6.1)
|
38
38
|
docile (1.4.1)
|
39
39
|
dotenv (2.8.1)
|
40
|
-
faraday (2.
|
40
|
+
faraday (2.13.1)
|
41
41
|
faraday-net_http (>= 2.0, < 3.5)
|
42
42
|
json
|
43
43
|
logger
|
44
44
|
faraday-net_http (3.4.0)
|
45
45
|
net-http (>= 0.5.0)
|
46
46
|
github-markup (5.0.1)
|
47
|
-
google-protobuf (3.25.
|
47
|
+
google-protobuf (3.25.7)
|
48
48
|
googleapis-common-protos-types (1.19.0)
|
49
49
|
google-protobuf (>= 3.18, < 5.a)
|
50
50
|
hashdiff (1.1.2)
|
51
51
|
io-console (0.8.0)
|
52
|
-
irb (1.15.
|
52
|
+
irb (1.15.2)
|
53
53
|
pp (>= 0.6.0)
|
54
54
|
rdoc (>= 4.0.0)
|
55
55
|
reline (>= 0.4.2)
|
56
|
-
json (2.
|
56
|
+
json (2.11.3)
|
57
57
|
language_server-protocol (3.17.0.4)
|
58
58
|
lint_roller (1.1.0)
|
59
|
-
logger (1.
|
59
|
+
logger (1.7.0)
|
60
60
|
net-http (0.6.0)
|
61
61
|
uri
|
62
62
|
opentelemetry-api (1.5.0)
|
@@ -255,8 +255,8 @@ GEM
|
|
255
255
|
opentelemetry-semantic_conventions
|
256
256
|
opentelemetry-semantic_conventions (1.11.0)
|
257
257
|
opentelemetry-api (~> 1.0)
|
258
|
-
parallel (1.
|
259
|
-
parser (3.3.
|
258
|
+
parallel (1.27.0)
|
259
|
+
parser (3.3.8.0)
|
260
260
|
ast (~> 2.4.1)
|
261
261
|
racc
|
262
262
|
pp (0.6.2)
|
@@ -271,11 +271,11 @@ GEM
|
|
271
271
|
rainbow (3.1.1)
|
272
272
|
rake (13.2.1)
|
273
273
|
rbtree (0.4.6)
|
274
|
-
rdoc (6.13.
|
274
|
+
rdoc (6.13.1)
|
275
275
|
psych (>= 4.0.0)
|
276
276
|
redcarpet (3.6.1)
|
277
277
|
regexp_parser (2.10.0)
|
278
|
-
reline (0.6.
|
278
|
+
reline (0.6.1)
|
279
279
|
io-console (~> 0.5)
|
280
280
|
rexml (3.4.1)
|
281
281
|
rsolr (2.6.0)
|
@@ -294,7 +294,7 @@ GEM
|
|
294
294
|
diff-lcs (>= 1.2.0, < 2.0)
|
295
295
|
rspec-support (~> 3.13.0)
|
296
296
|
rspec-support (3.13.2)
|
297
|
-
rubocop (1.
|
297
|
+
rubocop (1.75.3)
|
298
298
|
json (~> 2.3)
|
299
299
|
language_server-protocol (~> 3.17.0.2)
|
300
300
|
lint_roller (~> 1.1.0)
|
@@ -302,15 +302,15 @@ GEM
|
|
302
302
|
parser (>= 3.3.0.2)
|
303
303
|
rainbow (>= 2.2.2, < 4.0)
|
304
304
|
regexp_parser (>= 2.9.3, < 3.0)
|
305
|
-
rubocop-ast (>= 1.
|
305
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
306
306
|
ruby-progressbar (~> 1.7)
|
307
307
|
unicode-display_width (>= 2.4.0, < 4.0)
|
308
|
-
rubocop-ast (1.
|
308
|
+
rubocop-ast (1.44.1)
|
309
309
|
parser (>= 3.3.7.2)
|
310
310
|
prism (~> 1.4)
|
311
|
-
rubocop-performance (1.
|
311
|
+
rubocop-performance (1.25.0)
|
312
312
|
lint_roller (~> 1.1)
|
313
|
-
rubocop (>= 1.
|
313
|
+
rubocop (>= 1.75.0, < 2.0)
|
314
314
|
rubocop-ast (>= 1.38.0, < 2.0)
|
315
315
|
ruby-progressbar (1.13.0)
|
316
316
|
set (1.1.1)
|
@@ -326,19 +326,19 @@ GEM
|
|
326
326
|
sorted_set (1.0.3)
|
327
327
|
rbtree
|
328
328
|
set (~> 1.0)
|
329
|
-
standard (1.
|
329
|
+
standard (1.49.0)
|
330
330
|
language_server-protocol (~> 3.17.0.2)
|
331
331
|
lint_roller (~> 1.0)
|
332
|
-
rubocop (~> 1.
|
332
|
+
rubocop (~> 1.75.2)
|
333
333
|
standard-custom (~> 1.0.0)
|
334
|
-
standard-performance (~> 1.
|
334
|
+
standard-performance (~> 1.8)
|
335
335
|
standard-custom (1.0.2)
|
336
336
|
lint_roller (~> 1.0)
|
337
337
|
rubocop (~> 1.50)
|
338
|
-
standard-performance (1.
|
338
|
+
standard-performance (1.8.0)
|
339
339
|
lint_roller (~> 1.1)
|
340
|
-
rubocop-performance (~> 1.
|
341
|
-
stringio (3.1.
|
340
|
+
rubocop-performance (~> 1.25.0)
|
341
|
+
stringio (3.1.7)
|
342
342
|
unicode-display_width (3.1.4)
|
343
343
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
344
344
|
unicode-emoji (4.0.4)
|
@@ -370,4 +370,4 @@ DEPENDENCIES
|
|
370
370
|
yard (~> 0.9.37)
|
371
371
|
|
372
372
|
BUNDLED WITH
|
373
|
-
2.6.
|
373
|
+
2.6.7
|
data/README.md
CHANGED
@@ -44,12 +44,13 @@ explicitly with a `ConnectionConfig` object, or implicitly, reading a default
|
|
44
44
|
configuration with `ConnectionConfig#from_env`. `ConnectionConfig#from_env` expects
|
45
45
|
the following environment variables:
|
46
46
|
|
47
|
-
| Variable | Sample value | Description
|
48
|
-
|
49
|
-
| `RABBITMQ_HOST` | `rabbitmq` | Hostname of RabbitMQ server
|
50
|
-
| `RABBITMQ_NODE_PORT_NUMBER` | `5672` | Port name of RabbitMQ server
|
51
|
-
| `RABBITMQ_USERNAME` | `user` | RabbitMQ username
|
52
|
-
| `RABBITMQ_PASSWORD` | `bitnami` | RabbitMQ password
|
47
|
+
| Variable | Sample value | Description |
|
48
|
+
|-----------------------------|--------------|-----------------------------------------------------------|
|
49
|
+
| `RABBITMQ_HOST` | `rabbitmq` | Hostname of RabbitMQ server |
|
50
|
+
| `RABBITMQ_NODE_PORT_NUMBER` | `5672` | Port name of RabbitMQ server |
|
51
|
+
| `RABBITMQ_USERNAME` | `user` | RabbitMQ username |
|
52
|
+
| `RABBITMQ_PASSWORD` | `bitnami` | RabbitMQ password |
|
53
|
+
| `RABBITMQ_AWAIT_ON_CLOSE` | `false` | Whether to wait on response when closing (default = true) |
|
53
54
|
|
54
55
|
The `Mq::Connection#with_topic` and `Mq::Connection#topic_from` can either take an
|
55
56
|
explicit `TopicConfig` object, or implicitly read a default configuration with
|
@@ -28,26 +28,22 @@ module Surfliner
|
|
28
28
|
@config = not_nil!(config)
|
29
29
|
end
|
30
30
|
|
31
|
-
# Opens a
|
32
|
-
#
|
31
|
+
# Opens this connection and creates a channel. If a block is
|
32
|
+
# given, yields the open connection, closing the connection and
|
33
|
+
# channel afterwards; otherwise, returns the open connection.
|
34
|
+
# @return [self] an open connection
|
35
|
+
# @yieldparam connection [self] an open connection
|
33
36
|
# @raise [IOError] if already connected
|
34
37
|
def connect
|
35
|
-
|
38
|
+
init_connection
|
36
39
|
|
37
|
-
|
38
|
-
@session = Bunny.new(config.session_url, logger: logger)
|
39
|
-
connect_on(session)
|
40
|
-
@channel = session.create_channel
|
40
|
+
return self unless block_given?
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
rescue Bunny::PossibleAuthenticationFailureError => err
|
48
|
-
# TODO: realistically, this only happens in session.start, where we're eating it
|
49
|
-
logger.error("Failed to authenticate to #{config.redacted_url}")
|
50
|
-
raise err
|
42
|
+
begin
|
43
|
+
yield self
|
44
|
+
ensure
|
45
|
+
close
|
46
|
+
end
|
51
47
|
end
|
52
48
|
|
53
49
|
# Opens a session, yields a client for the specified topic, and closes the
|
@@ -55,11 +51,9 @@ module Surfliner
|
|
55
51
|
# @param config [TopicConfig] topic configuration
|
56
52
|
# @yield [MqTopic] A client for the topic
|
57
53
|
def with_topic(config = TopicConfig.from_env)
|
58
|
-
connect
|
59
|
-
|
60
|
-
|
61
|
-
ensure
|
62
|
-
close
|
54
|
+
connect do |cxn|
|
55
|
+
yield cxn.topic_from(config)
|
56
|
+
end
|
63
57
|
end
|
64
58
|
|
65
59
|
# Returns a client for the specified topic. Note that this does _not_ open
|
@@ -76,13 +70,9 @@ module Surfliner
|
|
76
70
|
|
77
71
|
# Closes the session.
|
78
72
|
def close
|
79
|
-
return unless channel
|
80
|
-
return if channel.closed?
|
81
|
-
logger.info("closing channel")
|
82
|
-
channel.close
|
83
|
-
ensure
|
84
73
|
logger.info("closing session")
|
85
|
-
|
74
|
+
# Note: This will also close any open channels
|
75
|
+
session&.close(config.await_response_on_close)
|
86
76
|
end
|
87
77
|
|
88
78
|
# @return [true, false] True if the session is open, false otherwise
|
@@ -107,6 +97,24 @@ module Surfliner
|
|
107
97
|
|
108
98
|
private
|
109
99
|
|
100
|
+
def init_connection
|
101
|
+
raise IOError, "RabbitMQ session #{session} already open." if open?
|
102
|
+
|
103
|
+
logger.info("Rabbitmq message broker session url: #{config.redacted_url}")
|
104
|
+
opts = {logger:}.merge(config.opts)
|
105
|
+
@session = Bunny.new(config.session_url, **opts)
|
106
|
+
connect_on(session)
|
107
|
+
@channel = session.create_channel
|
108
|
+
rescue Bunny::TCPConnectionFailed => err
|
109
|
+
# TODO: realistically, this only happens in session.start, where we're eating it
|
110
|
+
logger.error("Connection to #{config.redacted_url} failed")
|
111
|
+
raise err
|
112
|
+
rescue Bunny::PossibleAuthenticationFailureError => err
|
113
|
+
# TODO: realistically, this only happens in session.start, where we're eating it
|
114
|
+
logger.error("Failed to authenticate to #{config.redacted_url}")
|
115
|
+
raise err
|
116
|
+
end
|
117
|
+
|
110
118
|
def connect_on(session, timeout = 120)
|
111
119
|
timer = 0
|
112
120
|
logger.info "Trying to open queue session with timeout=#{timeout}"
|
@@ -2,6 +2,8 @@ module Surfliner
|
|
2
2
|
module Mq
|
3
3
|
# An object encapsulating RabbitMQ configuration.
|
4
4
|
class ConnectionConfig
|
5
|
+
FALSE_VALUES = ([""] + %w[0 off Off OFF f false False FALSE F n no No NO N]).freeze
|
6
|
+
|
5
7
|
# @return [String] The RabbitMQ hostname
|
6
8
|
attr_reader :host
|
7
9
|
|
@@ -14,36 +16,49 @@ module Surfliner
|
|
14
16
|
# @return [String] The RabbitMQ passsword
|
15
17
|
attr_reader :password
|
16
18
|
|
19
|
+
# @return [Boolean] whether the RabbitMQ client should wait for a response when closing the connection
|
20
|
+
attr_reader :await_response_on_close
|
21
|
+
|
22
|
+
# @return [Hash] Additional RabbitMQ connection options (see Bunny::Session#initialize)
|
23
|
+
attr_reader :opts
|
24
|
+
|
17
25
|
# Initializes a new `MqConfig` object.
|
18
26
|
# @param host [String] RabbitMQ hostname
|
19
27
|
# @param port [String] RabbitMQ AMQP port
|
20
28
|
# @param username [String] RabbitMQ username
|
21
29
|
# @param password [String] RabbitMQ passsword
|
22
|
-
|
30
|
+
# @param await_response_on_close [Boolean] whether the RabbitMQ client should wait for a response when closing the connection
|
31
|
+
# @param opts [Hash] additional RabbitMQ conection options (see Bunny::Session#initialize)
|
32
|
+
def initialize(host:, port:, username:, password:, await_response_on_close: true, **opts)
|
23
33
|
@host = host
|
24
34
|
@port = port
|
25
35
|
@username = username
|
26
36
|
@password = password
|
37
|
+
@await_response_on_close = parse_boolean(await_response_on_close)
|
38
|
+
@opts = opts
|
27
39
|
end
|
28
40
|
|
29
41
|
class << self
|
30
42
|
# Reads RabbitMQ configuration from environment variables and
|
31
43
|
# returns it as a new `ConnectionConfig` object.
|
32
44
|
#
|
33
|
-
# | Variable | Sample value | Description
|
34
|
-
#
|
35
|
-
# | `RABBITMQ_HOST` | `rabbitmq` | Hostname of RabbitMQ server
|
36
|
-
# | `RABBITMQ_NODE_PORT_NUMBER` | `5672` | Port name of RabbitMQ server
|
37
|
-
# | `RABBITMQ_USERNAME` | `user` | RabbitMQ username
|
38
|
-
# | `RABBITMQ_PASSWORD` | `bitnami` | RabbitMQ password
|
45
|
+
# | Variable | Sample value | Description |
|
46
|
+
# |-----------------------------|--------------|-----------------------------------------------------------|
|
47
|
+
# | `RABBITMQ_HOST` | `rabbitmq` | Hostname of RabbitMQ server |
|
48
|
+
# | `RABBITMQ_NODE_PORT_NUMBER` | `5672` | Port name of RabbitMQ server |
|
49
|
+
# | `RABBITMQ_USERNAME` | `user` | RabbitMQ username |
|
50
|
+
# | `RABBITMQ_PASSWORD` | `bitnami` | RabbitMQ password |
|
51
|
+
# | `RABBITMQ_AWAIT_ON_CLOSE` | `false` | Whether to wait on response when closing (default = true) |
|
39
52
|
#
|
40
53
|
# @return [ConnectionConfig] The configuration.
|
41
|
-
def from_env
|
54
|
+
def from_env(**opts)
|
42
55
|
ConnectionConfig.new(
|
43
56
|
host: ENV.fetch("RABBITMQ_HOST"),
|
44
57
|
port: ENV.fetch("RABBITMQ_NODE_PORT_NUMBER"),
|
45
58
|
username: ENV.fetch("RABBITMQ_USERNAME"),
|
46
|
-
password: ENV.fetch("RABBITMQ_PASSWORD")
|
59
|
+
password: ENV.fetch("RABBITMQ_PASSWORD"),
|
60
|
+
await_response_on_close: ENV.fetch("RABBITMQ_AWAIT_ON_CLOSE") || true,
|
61
|
+
**opts
|
47
62
|
)
|
48
63
|
end
|
49
64
|
end
|
@@ -57,6 +72,12 @@ module Surfliner
|
|
57
72
|
def redacted_url
|
58
73
|
@redacted_url ||= session_url.sub(password, "REDACTED")
|
59
74
|
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def parse_boolean(v)
|
79
|
+
!FALSE_VALUES.include?(v.to_s)
|
80
|
+
end
|
60
81
|
end
|
61
82
|
end
|
62
83
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surfliner-metadata_consumer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.alpha.
|
4
|
+
version: 0.1.0.pre.alpha.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Project Surfliner
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bunny
|
@@ -15,14 +15,14 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: '2.
|
18
|
+
version: '2.24'
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: '2.
|
25
|
+
version: '2.24'
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: opentelemetry-exporter-otlp
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -320,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
320
320
|
- !ruby/object:Gem::Version
|
321
321
|
version: '0'
|
322
322
|
requirements: []
|
323
|
-
rubygems_version: 3.6.
|
323
|
+
rubygems_version: 3.6.7
|
324
324
|
specification_version: 4
|
325
325
|
summary: Surfliner metadata consumer
|
326
326
|
test_files: []
|