surfliner-metadata_consumer 0.1.0.pre.alpha.1 → 0.1.0.pre.alpha.2
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/Gemfile +0 -1
- data/Gemfile.lock +12 -12
- data/README.md +2 -2
- data/bin/daylight-index-listen +3 -1
- data/bin/simulate-publish-event +8 -6
- data/lib/surfliner/metadata_consumer/consumer.rb +6 -4
- data/lib/surfliner/metadata_consumer/mq_connection.rb +42 -4
- data/lib/surfliner/metadata_consumer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22ceb6aaafb75d24e2cf646c3ac55eaca9c0fc92183a448f3ad3a09e9920eaea
|
4
|
+
data.tar.gz: 52c43074990eade7d93c32fa471329e845d2776f9229246f57bec81e75fa558d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f19622750625a84977122fa344b8635bac1d6f80de562237505be22f82aa3acbc532d53f768f0f3b9b7dbda84724d1979b9396e785dca25d30216b71b8746c65
|
7
|
+
data.tar.gz: 47621bc83433c05a36cd0d15a3b3a526eb981b0bd1085014c5179ea7c1dce0ad0a12722895873d629bfc1a510cb3648d1a5b2695d1b797d9960befcbb90e517e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
surfliner-metadata_consumer (0.1.0.pre.alpha.
|
4
|
+
surfliner-metadata_consumer (0.1.0.pre.alpha.2)
|
5
5
|
bunny (~> 2.23)
|
6
6
|
opentelemetry-exporter-otlp (~> 0.26.3)
|
7
7
|
opentelemetry-instrumentation-all (~> 0.60.0)
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
specs:
|
14
14
|
addressable (2.8.7)
|
15
15
|
public_suffix (>= 2.0.2, < 7.0)
|
16
|
-
amq-protocol (2.3.
|
16
|
+
amq-protocol (2.3.3)
|
17
17
|
ast (2.4.2)
|
18
18
|
bigdecimal (3.1.9)
|
19
19
|
builder (3.3.0)
|
@@ -34,7 +34,7 @@ GEM
|
|
34
34
|
debug (1.9.2)
|
35
35
|
irb (~> 1.10)
|
36
36
|
reline (>= 0.3.8)
|
37
|
-
diff-lcs (1.
|
37
|
+
diff-lcs (1.6.0)
|
38
38
|
docile (1.4.1)
|
39
39
|
dotenv (2.8.1)
|
40
40
|
faraday (2.12.2)
|
@@ -55,11 +55,11 @@ GEM
|
|
55
55
|
json (2.10.1)
|
56
56
|
language_server-protocol (3.17.0.4)
|
57
57
|
lint_roller (1.1.0)
|
58
|
-
logger (1.6.
|
58
|
+
logger (1.6.6)
|
59
59
|
net-http (0.6.0)
|
60
60
|
uri
|
61
|
-
opentelemetry-api (1.
|
62
|
-
opentelemetry-common (0.
|
61
|
+
opentelemetry-api (1.5.0)
|
62
|
+
opentelemetry-common (0.22.0)
|
63
63
|
opentelemetry-api (~> 1.0)
|
64
64
|
opentelemetry-exporter-otlp (0.26.3)
|
65
65
|
google-protobuf (~> 3.14)
|
@@ -245,14 +245,14 @@ GEM
|
|
245
245
|
opentelemetry-helpers-sql-obfuscation
|
246
246
|
opentelemetry-instrumentation-base (~> 0.22.1)
|
247
247
|
opentelemetry-semantic_conventions (>= 1.8.0)
|
248
|
-
opentelemetry-registry (0.
|
248
|
+
opentelemetry-registry (0.4.0)
|
249
249
|
opentelemetry-api (~> 1.1)
|
250
250
|
opentelemetry-sdk (1.4.1)
|
251
251
|
opentelemetry-api (~> 1.1)
|
252
252
|
opentelemetry-common (~> 0.20)
|
253
253
|
opentelemetry-registry (~> 0.2)
|
254
254
|
opentelemetry-semantic_conventions
|
255
|
-
opentelemetry-semantic_conventions (1.
|
255
|
+
opentelemetry-semantic_conventions (1.11.0)
|
256
256
|
opentelemetry-api (~> 1.0)
|
257
257
|
parallel (1.26.3)
|
258
258
|
parser (3.3.7.1)
|
@@ -274,7 +274,7 @@ GEM
|
|
274
274
|
regexp_parser (2.10.0)
|
275
275
|
reline (0.6.0)
|
276
276
|
io-console (~> 0.5)
|
277
|
-
rexml (3.4.
|
277
|
+
rexml (3.4.1)
|
278
278
|
rsolr (2.6.0)
|
279
279
|
builder (>= 2.1.2)
|
280
280
|
faraday (>= 0.9, < 3, != 2.0.0)
|
@@ -301,7 +301,7 @@ GEM
|
|
301
301
|
rubocop-ast (>= 1.38.0, < 2.0)
|
302
302
|
ruby-progressbar (~> 1.7)
|
303
303
|
unicode-display_width (>= 2.4.0, < 4.0)
|
304
|
-
rubocop-ast (1.38.
|
304
|
+
rubocop-ast (1.38.1)
|
305
305
|
parser (>= 3.3.1.0)
|
306
306
|
rubocop-performance (1.23.1)
|
307
307
|
rubocop (>= 1.48.1, < 2.0)
|
@@ -332,11 +332,11 @@ GEM
|
|
332
332
|
standard-performance (1.6.0)
|
333
333
|
lint_roller (~> 1.1)
|
334
334
|
rubocop-performance (~> 1.23.0)
|
335
|
-
stringio (3.1.
|
335
|
+
stringio (3.1.5)
|
336
336
|
unicode-display_width (3.1.4)
|
337
337
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
338
338
|
unicode-emoji (4.0.4)
|
339
|
-
uri (1.0.
|
339
|
+
uri (1.0.3)
|
340
340
|
webmock (3.25.0)
|
341
341
|
addressable (>= 2.8.0)
|
342
342
|
crack (>= 0.3.2)
|
data/README.md
CHANGED
@@ -61,11 +61,11 @@ a configured `SOLR_URL`, e.g.:
|
|
61
61
|
SOLR_URL=http://admin:admin@solr:8983/solr/daylight-dev
|
62
62
|
```
|
63
63
|
|
64
|
-
The `bin/simulate-publish-event` script expects an `
|
64
|
+
The `bin/simulate-publish-event` script expects an `METADATA_API_URL_BASE`, used to generate resource URLs
|
65
65
|
for provided IDs:
|
66
66
|
|
67
67
|
```sh
|
68
|
-
|
68
|
+
METADATA_API_URL_BASE=http://superskunk:3000/resources
|
69
69
|
```
|
70
70
|
|
71
71
|
## Solr / Daylight handler implementation
|
data/bin/daylight-index-listen
CHANGED
@@ -20,4 +20,6 @@ tracer = OpenTelemetry.tracer_provider.tracer("DaylightConsumerTracer")
|
|
20
20
|
|
21
21
|
handler = Surfliner::MetadataConsumer::Solr::MessageHandler
|
22
22
|
|
23
|
-
|
23
|
+
opts = { queue: { durable: false } }
|
24
|
+
|
25
|
+
Surfliner::MetadataConsumer::Consumer.run(logger:, tracer:, handler:, opts:)
|
data/bin/simulate-publish-event
CHANGED
@@ -6,18 +6,20 @@ require "logger"
|
|
6
6
|
|
7
7
|
require "surfliner/metadata_consumer/mq_connection"
|
8
8
|
|
9
|
-
api_base
|
10
|
-
logger
|
9
|
+
api_base = ENV.fetch("METADATA_API_URL_BASE") { "http://metadata.test/resources" }
|
10
|
+
logger = Logger.new($stdout)
|
11
11
|
logger.level = ENV.fetch("LOG_LEVEL") { Logger::INFO }
|
12
12
|
|
13
|
-
|
13
|
+
opts = { queue: { durable: false } }
|
14
|
+
|
15
|
+
connection = Surfliner::MetadataConsumer::MqConnection.new(logger:, opts:).connect
|
14
16
|
|
15
17
|
begin
|
16
18
|
ARGV.each do |id|
|
17
19
|
payload =
|
18
|
-
{resourceUrl: "#{api_base}
|
19
|
-
|
20
|
-
|
20
|
+
{ resourceUrl: "#{api_base}/#{id}",
|
21
|
+
status: :published,
|
22
|
+
time_stamp: DateTime.now }.to_json
|
21
23
|
|
22
24
|
logger.info "Publishing to #{connection.routing_key} with #{payload}"
|
23
25
|
connection.exchange.publish(payload, routing_key: connection.routing_key)
|
@@ -13,8 +13,9 @@ module Surfliner
|
|
13
13
|
# @param tracer [OpenTelemetry::Trace::Tracer] OpenTelemetry tracer
|
14
14
|
# @param logger [Logger] log message destination
|
15
15
|
# @param handler #handle an object accepting a JSON string
|
16
|
-
|
17
|
-
|
16
|
+
# @param opts [Hash] (see MqConnection#new)
|
17
|
+
def initialize(tracer:, logger:, handler:, opts: nil)
|
18
|
+
@connection = MqConnection.new(logger:, opts:)
|
18
19
|
@logger = logger
|
19
20
|
@tracer = tracer
|
20
21
|
@handler = handler
|
@@ -24,8 +25,9 @@ module Surfliner
|
|
24
25
|
# @param tracer [OpenTelemetry::Trace::Tracer] OpenTelemetry tracer
|
25
26
|
# @param logger [Logger] log message destination
|
26
27
|
# @param handler #handle an object accepting a JSON string payload
|
27
|
-
|
28
|
-
|
28
|
+
# @param opts [Hash] (see MqConnection#new)
|
29
|
+
def self.run(tracer:, logger:, handler:, opts: nil)
|
30
|
+
new(tracer:, logger:, handler:, opts:).run
|
29
31
|
end
|
30
32
|
|
31
33
|
# Starts listening to the message queue and passing messages to the handler.
|
@@ -4,6 +4,15 @@ module Surfliner
|
|
4
4
|
module MetadataConsumer
|
5
5
|
# An object encapsulating a RabbitMQ connection.
|
6
6
|
class MqConnection
|
7
|
+
# Default RabbitMQ topic options
|
8
|
+
DEFAULT_TOPIC_OPTS = {auto_delete: true}.freeze
|
9
|
+
|
10
|
+
# Default RabbitMQ queue options
|
11
|
+
DEFAULT_QUEUE_OPTS = {durable: true}.freeze
|
12
|
+
|
13
|
+
# Default RabbitMQ topic and queue options
|
14
|
+
DEFAULT_OPTS = {topic: DEFAULT_TOPIC_OPTS, queue: DEFAULT_QUEUE_OPTS}.freeze
|
15
|
+
|
7
16
|
# @return [Logger] The logger
|
8
17
|
attr_reader :logger
|
9
18
|
|
@@ -22,13 +31,18 @@ module Surfliner
|
|
22
31
|
# @return [MqConfig] The configuration
|
23
32
|
attr_reader :config
|
24
33
|
|
34
|
+
# @return [Hash<Symbol, Hash>] Options to pass when connecting to RabbitMQ topic and queue. Overrides DEFAULT_OPTS.
|
35
|
+
attr_reader :opts
|
36
|
+
|
25
37
|
# Initializes a new `MqConnection`.
|
26
38
|
#
|
27
39
|
# @param logger [Logger] the logger
|
28
40
|
# @param config [MqConfig] the configuration
|
29
|
-
|
41
|
+
# @param opts [Hash<Symbol, Hash>] Options to pass when connecting to RabbitMQ topic and queue. Overrides DEFAULT_OPTS.
|
42
|
+
def initialize(logger:, config: MqConfig.from_env, opts: nil)
|
30
43
|
@logger = logger
|
31
44
|
@config = config
|
45
|
+
@opts = merge_opts(opts)
|
32
46
|
end
|
33
47
|
|
34
48
|
# Opens a connection.
|
@@ -41,8 +55,8 @@ module Surfliner
|
|
41
55
|
@connection = Bunny.new(config.connection_url, logger: logger)
|
42
56
|
connect_on(connection)
|
43
57
|
@channel = connection.create_channel
|
44
|
-
@exchange = channel.topic(config.topic,
|
45
|
-
@queue = channel.queue(config.queue_name,
|
58
|
+
@exchange = channel.topic(config.topic, topic_opts)
|
59
|
+
@queue = channel.queue(config.queue_name, queue_opts)
|
46
60
|
queue.bind(exchange, routing_key: config.routing_key)
|
47
61
|
|
48
62
|
self
|
@@ -68,8 +82,12 @@ module Surfliner
|
|
68
82
|
|
69
83
|
# Closes the connection.
|
70
84
|
def close
|
71
|
-
channel
|
85
|
+
return unless channel
|
86
|
+
return if channel.closed?
|
87
|
+
logger.info("closing channel")
|
88
|
+
channel.close
|
72
89
|
ensure
|
90
|
+
logger.info("closing connection")
|
73
91
|
connection&.close
|
74
92
|
end
|
75
93
|
|
@@ -93,8 +111,28 @@ module Surfliner
|
|
93
111
|
config.port
|
94
112
|
end
|
95
113
|
|
114
|
+
# @return [Hash] Options passed when connecting to RabbitMQ topic
|
115
|
+
def topic_opts
|
116
|
+
opts[:topic]
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [Hash] Options passed when connecting to RabbitMQ queue
|
120
|
+
def queue_opts
|
121
|
+
opts[:queue]
|
122
|
+
end
|
123
|
+
|
96
124
|
private
|
97
125
|
|
126
|
+
def merge_opts(opts)
|
127
|
+
DEFAULT_OPTS.to_h do |opt_type, opts_default|
|
128
|
+
opts_actual = opts_default.dup
|
129
|
+
if opts && (opts_provided = opts[opt_type])
|
130
|
+
opts_actual.merge!(opts_provided)
|
131
|
+
end
|
132
|
+
[opt_type, opts_actual]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
98
136
|
def connect_on(connection, timeout = 120)
|
99
137
|
timer = 0
|
100
138
|
logger.info "Trying to open queue connection with timeout=#{timeout}"
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Project Surfliner
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bunny
|