sbmt-outbox 6.3.0 → 6.4.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.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/app/controllers/sbmt/outbox/api/inbox_classes_controller.rb +1 -1
- data/app/controllers/sbmt/outbox/api/outbox_classes_controller.rb +1 -1
- data/app/models/sbmt/outbox/base_item.rb +5 -1
- data/app/models/sbmt/outbox/base_item_config.rb +5 -4
- data/lib/generators/outbox/install/templates/outbox.yml +2 -0
- data/lib/sbmt/outbox/cli.rb +1 -1
- data/lib/sbmt/outbox/engine.rb +1 -1
- data/lib/sbmt/outbox/probes/metrics.rb +52 -0
- data/lib/sbmt/outbox/probes/probe.rb +10 -0
- data/lib/sbmt/outbox/version.rb +1 -1
- data/lib/sbmt/outbox.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aed7afb062770ab592517d363d16fa57428a29b9e67ec83eb65c5ceacbfba714
|
4
|
+
data.tar.gz: eafe1f3ea486c9913a82508a7e20a423e6eb6789651d7cb0642e706fa233a609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e58e6a80a6bd1a2ec1f9f41816d2b70532ae2e58b29f8588d5c326d22617fdbeb8e321fa70d2d02773ac6d0ff07403047351eb7ea89ff1597b9708ff66b69909
|
7
|
+
data.tar.gz: fe734a0361f7a749b23f63074faa5c3c1d3b9c92fad1e997ca4603a64a2efb30550f7a62c22a96f2830c0ef8fb1be0650fb6cd7a3a62100a63245d3631834580
|
data/README.md
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
|
4
4
|
# Sbmt-Outbox
|
5
5
|
|
6
|
+
<img src="https://raw.githubusercontent.com/SberMarket-Tech/sbmt-outbox/master/.github/outbox-logo.png" alt="sbmt-outbox logo" height="220" align="right" />
|
7
|
+
|
6
8
|
Microservices often publish messages after a transaction has been committed. Writing to the database and publishing a message are two separate transactions, so they must be atomic. A failed publication of a message could lead to a critical failure of the business process.
|
7
9
|
|
8
10
|
The Outbox pattern provides a reliable solution for message publishing. The idea behind this approach is to have an "outgoing message table" in the service's database. Before the main transaction completes, a new message row is added to this table. As a result, two actions take place as part of a single transaction. An asynchronous process retrieves new rows from the database table and, if they exist, publishes the messages to the broker.
|
9
11
|
|
10
|
-
Read more about the Outbox pattern at https://microservices.io/patterns/data/transactional-outbox.html
|
11
|
-
|
12
12
|
## Installation
|
13
13
|
|
14
14
|
Add this line to your application's Gemfile:
|
@@ -224,7 +224,11 @@ The `outbox.yml` configuration file is the main configuration for the gem, where
|
|
224
224
|
default: &default
|
225
225
|
owner: foo-team # optional, used in Yabeda metrics
|
226
226
|
bucket_size: 16 # optional, default 16, see into about the buckets at the #Concurrency section
|
227
|
+
metrics:
|
228
|
+
enabled: true # default false, yabeda server autostart with port: 9090 and path: /metrics
|
229
|
+
port: 9090 # optional, default, used in Yabeda metrics
|
227
230
|
probes:
|
231
|
+
enabled: false # optional, default true
|
228
232
|
port: 5555 # default, used for Kubernetes probes
|
229
233
|
|
230
234
|
outbox_items: # outbox items section
|
@@ -6,7 +6,7 @@ module Sbmt
|
|
6
6
|
class InboxClassesController < BaseController
|
7
7
|
def index
|
8
8
|
render_list(Sbmt::Outbox.inbox_item_classes.map do |item|
|
9
|
-
Sbmt::Outbox::Api::InboxClass.find_or_initialize(item.
|
9
|
+
Sbmt::Outbox::Api::InboxClass.find_or_initialize(item.box_id)
|
10
10
|
end)
|
11
11
|
end
|
12
12
|
|
@@ -16,8 +16,12 @@ module Sbmt
|
|
16
16
|
@box_name ||= name.underscore
|
17
17
|
end
|
18
18
|
|
19
|
+
def box_id
|
20
|
+
@box_id ||= name.underscore.tr("/", "-").dasherize
|
21
|
+
end
|
22
|
+
|
19
23
|
def config
|
20
|
-
@config ||= lookup_config.new(box_name)
|
24
|
+
@config ||= lookup_config.new(box_id: box_id, box_name: box_name)
|
21
25
|
end
|
22
26
|
|
23
27
|
def calc_bucket_partitions(count)
|
@@ -8,7 +8,8 @@ module Sbmt
|
|
8
8
|
|
9
9
|
delegate :yaml_config, :memory_store, to: "Sbmt::Outbox"
|
10
10
|
|
11
|
-
def initialize(box_name)
|
11
|
+
def initialize(box_id:, box_name:)
|
12
|
+
self.box_id = box_id
|
12
13
|
self.box_name = box_name
|
13
14
|
|
14
15
|
validate!
|
@@ -109,7 +110,7 @@ module Sbmt
|
|
109
110
|
|
110
111
|
private
|
111
112
|
|
112
|
-
attr_accessor :box_name
|
113
|
+
attr_accessor :box_id, :box_name
|
113
114
|
|
114
115
|
def options
|
115
116
|
@options ||= lookup_config || {}
|
@@ -129,8 +130,8 @@ module Sbmt
|
|
129
130
|
end
|
130
131
|
|
131
132
|
def polling_enabled_for?(api_model)
|
132
|
-
record = memory_store.fetch("sbmt/outbox/outbox_item_config/#{
|
133
|
-
api_model.find(
|
133
|
+
record = memory_store.fetch("sbmt/outbox/outbox_item_config/#{box_id}", expires_in: 10) do
|
134
|
+
api_model.find(box_id)
|
134
135
|
end
|
135
136
|
|
136
137
|
if record.nil?
|
data/lib/sbmt/outbox/cli.rb
CHANGED
@@ -69,8 +69,8 @@ module Sbmt
|
|
69
69
|
$stdout.puts AsciiArt.logo
|
70
70
|
$stdout.puts "Outbox/Inbox worker has been started"
|
71
71
|
$stdout.puts "Version: #{VERSION}"
|
72
|
-
$stdout.puts "Starting probes..."
|
73
72
|
Sbmt::Outbox::Probes::Probe.run_probes
|
73
|
+
Sbmt::Outbox::Probes::Metrics.run_metrics
|
74
74
|
|
75
75
|
worker.start
|
76
76
|
end
|
data/lib/sbmt/outbox/engine.rb
CHANGED
@@ -22,7 +22,7 @@ module Sbmt
|
|
22
22
|
c.ui = ActiveSupport::OrderedOptions.new.tap do |c|
|
23
23
|
c.serve_local = false
|
24
24
|
c.local_endpoint = "http://localhost:5173"
|
25
|
-
c.cdn_url = "https://cdn.jsdelivr.net/npm/sbmt-outbox-ui@0.0.
|
25
|
+
c.cdn_url = "https://cdn.jsdelivr.net/npm/sbmt-outbox-ui@0.0.8/dist/assets/index.js"
|
26
26
|
end
|
27
27
|
c.process_items = ActiveSupport::OrderedOptions.new.tap do |c|
|
28
28
|
c.general_timeout = 120
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sbmt
|
4
|
+
module Outbox
|
5
|
+
module Probes
|
6
|
+
class Metrics
|
7
|
+
DEFAULT_YABEDA_PORT = 9090
|
8
|
+
DEFAULT_YABEDA_PATH = "/metrics"
|
9
|
+
class << self
|
10
|
+
def run_metrics
|
11
|
+
return unless autostart_yabeda_server?
|
12
|
+
|
13
|
+
if defined?(Yabeda)
|
14
|
+
$stdout.puts "Starting metrics http-server..."
|
15
|
+
|
16
|
+
start_webrick(
|
17
|
+
Yabeda::Prometheus::Mmap::Exporter::NOT_FOUND_HANDLER,
|
18
|
+
middlewares: {::Yabeda::Prometheus::Exporter => {path: DEFAULT_YABEDA_PATH}},
|
19
|
+
port: yabeda_port
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def yabeda_port
|
27
|
+
Sbmt::Outbox.yaml_config.dig(:metrics, :port) || DEFAULT_YABEDA_PORT
|
28
|
+
end
|
29
|
+
|
30
|
+
def start_webrick(app, middlewares:, port:)
|
31
|
+
Thread.new do
|
32
|
+
::Rack::Handler::WEBrick.run(
|
33
|
+
::Rack::Builder.new do
|
34
|
+
middlewares.each do |middleware, options|
|
35
|
+
use middleware, **options
|
36
|
+
end
|
37
|
+
run app
|
38
|
+
end,
|
39
|
+
Host: "0.0.0.0",
|
40
|
+
Port: port
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def autostart_yabeda_server?
|
46
|
+
Sbmt::Outbox.yaml_config.dig(:metrics, :enabled) || false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -7,6 +7,10 @@ module Sbmt
|
|
7
7
|
DEFAULT_PROBE_PORT = 5555
|
8
8
|
class << self
|
9
9
|
def run_probes
|
10
|
+
return unless autostart_probe?
|
11
|
+
|
12
|
+
$stdout.puts "Starting probes..."
|
13
|
+
|
10
14
|
::HttpHealthCheck.run_server_async(
|
11
15
|
port: probe_port,
|
12
16
|
rack_app: HttpHealthCheck::RackApp.configure do |c|
|
@@ -31,6 +35,12 @@ module Sbmt
|
|
31
35
|
|
32
36
|
Sbmt::Outbox.yaml_config.fetch(:probes).fetch(:port)
|
33
37
|
end
|
38
|
+
|
39
|
+
def autostart_probe?
|
40
|
+
value = Sbmt::Outbox.yaml_config.dig(:probes, :enabled)
|
41
|
+
value = true if value.nil?
|
42
|
+
value
|
43
|
+
end
|
34
44
|
end
|
35
45
|
end
|
36
46
|
end
|
data/lib/sbmt/outbox/version.rb
CHANGED
data/lib/sbmt/outbox.rb
CHANGED
@@ -38,6 +38,7 @@ require_relative "outbox/engine"
|
|
38
38
|
require_relative "outbox/middleware/builder"
|
39
39
|
require_relative "outbox/middleware/runner"
|
40
40
|
require_relative "outbox/probes/probe"
|
41
|
+
require_relative "outbox/probes/metrics"
|
41
42
|
require_relative "outbox/redis_client_factory"
|
42
43
|
|
43
44
|
module Sbmt
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbmt-outbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sbermarket Ruby-Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -586,6 +586,7 @@ files:
|
|
586
586
|
- lib/sbmt/outbox/middleware/sentry/tracing_batch_process_middleware.rb
|
587
587
|
- lib/sbmt/outbox/middleware/sentry/tracing_item_process_middleware.rb
|
588
588
|
- lib/sbmt/outbox/middleware/sentry/transaction.rb
|
589
|
+
- lib/sbmt/outbox/probes/metrics.rb
|
589
590
|
- lib/sbmt/outbox/probes/probe.rb
|
590
591
|
- lib/sbmt/outbox/redis_client_factory.rb
|
591
592
|
- lib/sbmt/outbox/tasks/delete_failed_items.rake
|