boom_nats 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish-ruby-gem.yml +23 -0
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/boom_nats/application.rb +45 -26
- data/lib/boom_nats/requester.rb +22 -0
- data/lib/boom_nats/version.rb +1 -1
- data/lib/boom_nats.rb +1 -0
- 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: a7f350fa4276eaa4271920061a3fe7d501ccfdb836bf792c2dceb9be98ad7059
|
4
|
+
data.tar.gz: 8b4b331934c8fc4fccb05e84b543c13cd8c456a31591b6e723e2d0662ce408d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02275442dc9e042dc0f02c1d1ddff6247b614ab3212876399d8be444a8464ded94d69c1d6c96661878f114107587f48bd69468a52bb8b8549c6d5e4ca03314b8
|
7
|
+
data.tar.gz: b5a13adfbc86d2b8d42deccab1967b4ee92ce00a958eb77fc97309d6e7c21b74a92ea99d1f86140dc8a62d7810260202689125e9b1844bed3ef208ba399bc758
|
@@ -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/Gemfile.lock
CHANGED
@@ -4,7 +4,7 @@ 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 = []
|
@@ -14,8 +14,7 @@ module BoomNats
|
|
14
14
|
|
15
15
|
def servers(value)
|
16
16
|
stop
|
17
|
-
|
18
|
-
@nats = nats_connect(value)
|
17
|
+
@server = value
|
19
18
|
end
|
20
19
|
|
21
20
|
def draw_routes(&block)
|
@@ -29,30 +28,38 @@ module BoomNats
|
|
29
28
|
instance_eval(&block) if block_given?
|
30
29
|
end
|
31
30
|
|
31
|
+
def nats
|
32
|
+
NATS
|
33
|
+
end
|
34
|
+
|
32
35
|
def start
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
Thread.new do
|
37
|
+
nats_connect do |nats|
|
38
|
+
@route_topics.each do |rt|
|
39
|
+
@subscriptions << nats.subscribe(rt.topic, rt.options) do |msg, reply, _sub|
|
40
|
+
rt.executor.new(msg, reply, nats, rt.serializer, rt.parser)
|
41
|
+
end
|
42
|
+
end
|
38
43
|
|
39
|
-
|
44
|
+
BoomNats.logger.debug "BoomNats::started"
|
40
45
|
|
41
|
-
|
46
|
+
return if defined?(Rails::Railtie)
|
42
47
|
|
43
|
-
|
48
|
+
prepare_trap
|
49
|
+
end
|
50
|
+
end
|
44
51
|
|
45
52
|
wait
|
46
53
|
end
|
47
54
|
|
48
55
|
def stop
|
49
|
-
@subscriptions.each { |s|
|
56
|
+
@subscriptions.each { |s| nats.unsubscribe(s) }
|
50
57
|
@subscriptions = []
|
51
58
|
|
52
59
|
# disconnect from old server if already configured
|
53
|
-
if
|
54
|
-
|
55
|
-
|
60
|
+
if nats&.connected?
|
61
|
+
nats.drain do
|
62
|
+
nats.stop
|
56
63
|
end
|
57
64
|
end
|
58
65
|
end
|
@@ -68,21 +75,33 @@ module BoomNats
|
|
68
75
|
end
|
69
76
|
end
|
70
77
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
ch = Concurrent::Channel.new
|
78
|
+
def execute(&block)
|
79
|
+
timeout = Concurrent::Cancellation.timeout 5
|
80
|
+
done = Concurrent::Channel.new(capacity: 1)
|
75
81
|
Concurrent::Channel.go do
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
loop do
|
83
|
+
@mutex.synchronize do
|
84
|
+
done << true if nats.connected?
|
85
|
+
end
|
86
|
+
|
87
|
+
done << false if timeout.origin.resolved?
|
82
88
|
end
|
83
89
|
end
|
84
90
|
|
85
|
-
|
91
|
+
if ~done
|
92
|
+
block.call(nats)
|
93
|
+
else
|
94
|
+
raise "Nats do not connected", BoomNats::Error
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
def nats_connect(&block)
|
101
|
+
NATS.start({
|
102
|
+
servers: @server,
|
103
|
+
**(nats_options.is_a?(Hash) ? nats_options : {})
|
104
|
+
}, &block)
|
86
105
|
end
|
87
106
|
|
88
107
|
def prepare_trap
|
@@ -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
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.1
|
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-05 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: []
|