boom_nats 0.1.0 → 0.1.4
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/.github/workflows/publish-ruby-gem.yml +23 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +9 -1
- data/Gemfile.lock +1 -1
- data/README.md +14 -11
- data/lib/boom_nats/application.rb +61 -27
- data/lib/boom_nats/railtie.rb +3 -3
- data/lib/boom_nats/requester.rb +22 -0
- data/lib/boom_nats/version.rb +1 -1
- data/lib/boom_nats.rb +4 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 240377b01a1661ec8dc00f36e3d5eddc80abae070ac7f82524ba299906773708
|
4
|
+
data.tar.gz: '0944ef91d75ee03479fef1efa3719f5040b534ec167ccf40796f7188672f17e2'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0353aeed0d8c4d10e469eedebcb5fdc46ed5cc0e3e157e4fa64c46b4b56adafb3339a1ef1d85d0d50c211985c4acc50abab217336f7a26b1b385d1f6d6a05eb5
|
7
|
+
data.tar.gz: ea5b643b06af129bfe1f10baa1ad3a05cc8e3b7f9553ba46288610c77e0a381c65133b0f9aa9106872f475ae72f970b4788445e6e1ea17facaf5c56eb2efc589
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Publish to Rubygem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- v*
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
publish:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: 3.0.2
|
17
|
+
bundler-cache: true
|
18
|
+
- name: build gem
|
19
|
+
run: gem build
|
20
|
+
- name: publish to Rubygems
|
21
|
+
env:
|
22
|
+
GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
|
23
|
+
run: gem push boom_nats-*.gem
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
##
|
1
|
+
## v0.1.4 - 2021-10-19
|
2
|
+
|
3
|
+
- FEAT: add initializers callback system after application start
|
4
|
+
|
5
|
+
## v0.1.3 - 2021-10-06
|
6
|
+
|
7
|
+
- BUG: fix Zeitwerk eager loading classes Rails::Railtie class not found
|
8
|
+
|
9
|
+
## v0.1.2 - 2021-10-05
|
2
10
|
|
3
11
|
- Standalone version
|
4
12
|
- Rails based version
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,14 +5,18 @@ NATS is a simple, secure and performant communications system for digital system
|
|
5
5
|
This implementation works in both modes: Standalone and Rails based applications.
|
6
6
|
|
7
7
|
## Documentation
|
8
|
-
|
9
|
-
- [
|
10
|
-
- [
|
11
|
-
- [
|
12
|
-
- [
|
13
|
-
|
14
|
-
|
15
|
-
- [
|
8
|
+
|
9
|
+
- [BoomNats](#boomnats)
|
10
|
+
- [Documentation](#documentation)
|
11
|
+
- [configurations](#configurations)
|
12
|
+
- [Rails](#rails)
|
13
|
+
- [Rails Installing](#rails-installing)
|
14
|
+
- [Rails Configuration](#rails-configuration)
|
15
|
+
- [Standalone](#standalone)
|
16
|
+
- [Standalone Installing](#standalone-installing)
|
17
|
+
- [Standalone Configuration](#standalone-configuration)
|
18
|
+
- [Standalone Starting Application](#standalone-starting-application)
|
19
|
+
|
16
20
|
## configurations
|
17
21
|
|
18
22
|
```ruby
|
@@ -28,7 +32,7 @@ BoomNats.setup do
|
|
28
32
|
|
29
33
|
# with authentication
|
30
34
|
servers "nats://user:pass@localhost:4222"
|
31
|
-
|
35
|
+
|
32
36
|
|
33
37
|
# map NATS topics to Topic classes
|
34
38
|
draw_routes do
|
@@ -86,7 +90,6 @@ rails g boom_nats:consumer PaymentGetter
|
|
86
90
|
# creates file: app/consumers/payment_getter_consumer.rb
|
87
91
|
```
|
88
92
|
|
89
|
-
|
90
93
|
## Standalone
|
91
94
|
|
92
95
|
To facilitate learning, you can download the default repository containing a boilerplate project with (Ruby, Nats and ActiveRecord)
|
@@ -108,7 +111,7 @@ gem install boom_nats
|
|
108
111
|
With bundle, add gem to Gemfile
|
109
112
|
|
110
113
|
```ruby
|
111
|
-
gem 'boom_nats', '~> 0.1.
|
114
|
+
gem 'boom_nats', '~> 0.1.2'
|
112
115
|
```
|
113
116
|
|
114
117
|
### Standalone Configuration
|
@@ -4,18 +4,22 @@ require "concurrent-edge"
|
|
4
4
|
module BoomNats
|
5
5
|
class Application
|
6
6
|
attr_accessor :router, :nats_options
|
7
|
-
attr_reader :route_topics
|
7
|
+
attr_reader :route_topics
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@route_topics = []
|
11
11
|
@subscriptions = []
|
12
|
+
@callbacks = {
|
13
|
+
before: [],
|
14
|
+
after: []
|
15
|
+
}
|
16
|
+
|
12
17
|
@mutex = Mutex.new
|
13
18
|
end
|
14
19
|
|
15
20
|
def servers(value)
|
16
21
|
stop
|
17
|
-
|
18
|
-
@nats = nats_connect(value)
|
22
|
+
@server = value
|
19
23
|
end
|
20
24
|
|
21
25
|
def draw_routes(&block)
|
@@ -29,30 +33,48 @@ module BoomNats
|
|
29
33
|
instance_eval(&block) if block_given?
|
30
34
|
end
|
31
35
|
|
36
|
+
def nats
|
37
|
+
NATS
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_before(&block)
|
41
|
+
@callbacks[:before] << block
|
42
|
+
end
|
43
|
+
|
44
|
+
def on_after(&block)
|
45
|
+
@callbacks[:after] << block
|
46
|
+
end
|
47
|
+
|
32
48
|
def start
|
33
|
-
|
34
|
-
@
|
35
|
-
rt.executor.new(msg, reply, @nats, rt.serializer, rt.parser)
|
36
|
-
end
|
37
|
-
end
|
49
|
+
Thread.new do
|
50
|
+
@callbacks[:before].each { |callback| callback.call(self) }
|
38
51
|
|
39
|
-
|
52
|
+
nats_connect do |nats|
|
53
|
+
@route_topics.each do |rt|
|
54
|
+
@subscriptions << nats.subscribe(rt.topic, rt.options) do |msg, reply, _sub|
|
55
|
+
rt.executor.new(msg, reply, nats, rt.serializer, rt.parser)
|
56
|
+
end
|
57
|
+
end
|
40
58
|
|
41
|
-
|
59
|
+
BoomNats.logger.debug "BoomNats::started"
|
42
60
|
|
43
|
-
|
61
|
+
prepare_trap unless defined?(Rails::Railtie)
|
44
62
|
|
45
|
-
|
63
|
+
@callbacks[:after].each { |callback| callback.call(self) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
wait unless defined?(Rails::Railtie)
|
46
68
|
end
|
47
69
|
|
48
70
|
def stop
|
49
|
-
@subscriptions.each { |s|
|
71
|
+
@subscriptions.each { |s| nats.unsubscribe(s) }
|
50
72
|
@subscriptions = []
|
51
73
|
|
52
74
|
# disconnect from old server if already configured
|
53
|
-
if
|
54
|
-
|
55
|
-
|
75
|
+
if nats&.connected?
|
76
|
+
nats.drain do
|
77
|
+
nats.stop
|
56
78
|
end
|
57
79
|
end
|
58
80
|
end
|
@@ -68,21 +90,33 @@ module BoomNats
|
|
68
90
|
end
|
69
91
|
end
|
70
92
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
ch = Concurrent::Channel.new
|
93
|
+
def execute(&block)
|
94
|
+
timeout = Concurrent::Cancellation.timeout 5
|
95
|
+
done = Concurrent::Channel.new(capacity: 1)
|
75
96
|
Concurrent::Channel.go do
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
97
|
+
loop do
|
98
|
+
@mutex.synchronize do
|
99
|
+
done << true if nats.connected?
|
100
|
+
end
|
101
|
+
|
102
|
+
done << false if timeout.origin.resolved?
|
82
103
|
end
|
83
104
|
end
|
84
105
|
|
85
|
-
|
106
|
+
if ~done
|
107
|
+
block.call(nats)
|
108
|
+
else
|
109
|
+
raise "Nats do not connected", BoomNats::Error
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
protected
|
114
|
+
|
115
|
+
def nats_connect(&block)
|
116
|
+
NATS.start({
|
117
|
+
servers: @server,
|
118
|
+
**(nats_options.is_a?(Hash) ? nats_options : {})
|
119
|
+
}, &block)
|
86
120
|
end
|
87
121
|
|
88
122
|
def prepare_trap
|
data/lib/boom_nats/railtie.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module BoomNats
|
2
|
-
class Railtie < Rails::Railtie
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
3
|
initializer "activeservice.autoload", before: :set_autoload_paths do |app|
|
4
4
|
# app.config.autoload_paths << ActiveService::Configuration.path
|
5
|
-
app.config.eager_load_paths << Rails.root.join("app", "consumers").to_s
|
5
|
+
app.config.eager_load_paths << ::Rails.root.join("app", "consumers").to_s
|
6
6
|
end
|
7
7
|
|
8
8
|
initializer "boom_nats.railtie.configure_rails_initialization" do |app|
|
9
9
|
app.config.nats = BoomNats.setup
|
10
|
-
BoomNats.logger = Rails.logger
|
10
|
+
BoomNats.logger = ::Rails.logger
|
11
11
|
end
|
12
12
|
|
13
13
|
server do |app|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BoomNats
|
2
|
+
module Requester
|
3
|
+
def request(topic, params = nil, options = {})
|
4
|
+
result = nil
|
5
|
+
BoomNats.application.execute do |nats|
|
6
|
+
timeout = Concurrent::Cancellation.timeout 5
|
7
|
+
done = Concurrent::Channel.new(capacity: 1)
|
8
|
+
Concurrent::Channel.go do
|
9
|
+
nats.request(topic, params.to_json, options) do |msg|
|
10
|
+
done << JSON.parse(msg)
|
11
|
+
end
|
12
|
+
timeout.origin.wait
|
13
|
+
done << BoomNats::Error.new("request do not received")
|
14
|
+
end
|
15
|
+
result = ~done # block until signaled
|
16
|
+
end
|
17
|
+
raise result if result.is_a?(BoomNats::Error)
|
18
|
+
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/boom_nats/version.rb
CHANGED
data/lib/boom_nats.rb
CHANGED
@@ -6,16 +6,19 @@ require "active_support/core_ext/module/attribute_accessors"
|
|
6
6
|
|
7
7
|
loader = Zeitwerk::Loader.for_gem
|
8
8
|
loader.setup
|
9
|
+
loader.ignore("#{__dir__}/boom_nats/railtie.rb")
|
10
|
+
loader.ignore("#{__dir__}/generators/**/*.rb")
|
9
11
|
|
10
12
|
module BoomNats
|
11
13
|
class Error < StandardError; end
|
12
14
|
|
13
15
|
extend BoomNats::Serializer
|
14
16
|
extend BoomNats::Setup
|
17
|
+
extend BoomNats::Requester
|
15
18
|
|
16
19
|
mattr_accessor :logger
|
17
20
|
end
|
18
21
|
|
19
22
|
BoomNats.logger = Logger.new(STDOUT)
|
20
23
|
|
21
|
-
require "boom_nats/railtie" if defined?(Rails::Railtie)
|
24
|
+
require "boom_nats/railtie" if defined?(::Rails::Railtie)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boom_nats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Welington Sampaio
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -114,6 +114,7 @@ extra_rdoc_files: []
|
|
114
114
|
files:
|
115
115
|
- ".editorconfig"
|
116
116
|
- ".github/workflows/main.yml"
|
117
|
+
- ".github/workflows/publish-ruby-gem.yml"
|
117
118
|
- ".gitignore"
|
118
119
|
- ".rspec"
|
119
120
|
- ".rubocop.yml"
|
@@ -131,6 +132,7 @@ files:
|
|
131
132
|
- lib/boom_nats.rb
|
132
133
|
- lib/boom_nats/application.rb
|
133
134
|
- lib/boom_nats/railtie.rb
|
135
|
+
- lib/boom_nats/requester.rb
|
134
136
|
- lib/boom_nats/route_topic.rb
|
135
137
|
- lib/boom_nats/router.rb
|
136
138
|
- lib/boom_nats/serializer.rb
|
@@ -148,7 +150,7 @@ metadata:
|
|
148
150
|
homepage_uri: https://opensource.alboompro.com/#alboom-nats-rb
|
149
151
|
source_code_uri: https://github.com/alboompro/alboom-nats-rb
|
150
152
|
changelog_uri: https://github.com/alboompro/alboom-nats-rb/master/Changelog
|
151
|
-
post_install_message:
|
153
|
+
post_install_message:
|
152
154
|
rdoc_options: []
|
153
155
|
require_paths:
|
154
156
|
- lib
|
@@ -163,8 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
165
|
- !ruby/object:Gem::Version
|
164
166
|
version: '0'
|
165
167
|
requirements: []
|
166
|
-
rubygems_version: 3.2.
|
167
|
-
signing_key:
|
168
|
+
rubygems_version: 3.2.22
|
169
|
+
signing_key:
|
168
170
|
specification_version: 4
|
169
171
|
summary: Native NATS integration server to standalone or Rails based app
|
170
172
|
test_files: []
|