bps-stan 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bps-stan.gemspec +1 -1
- data/lib/bps/publisher/stan.rb +11 -2
- data/spec/bps/stan_spec.rb +10 -9
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d0067ac2cf8b4ee41b4f7ff5f33c1ee6eff75304cd4c5775b753b1f126f100
|
4
|
+
data.tar.gz: 64c67e20c09fbe73f8e72512a4d9320551d518c962e2297f536a806270351748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80d8471eb192dd551615b1c0f8c8278dd3bc9e578dc4ebdf1a0844162a95a32c639eb3047572c692323756085b3bacb5d3c658dd4e1f73c27637e86335fda151
|
7
|
+
data.tar.gz: 3af18785c7eb3ab110dc0966e7800797fe1b387104311c6736f1ad91621152a4b2d27b628021d7bcbeae880dd39ea4d90b7a8053ebdf986928f31527d2360bf0
|
data/bps-stan.gemspec
CHANGED
data/lib/bps/publisher/stan.rb
CHANGED
@@ -28,6 +28,7 @@ module BPS
|
|
28
28
|
reconnect_time_wait: :float,
|
29
29
|
max_reconnect_attempts: :int,
|
30
30
|
connect_timeout: :float,
|
31
|
+
tls_ca_file: :string,
|
31
32
|
# TODO: review, list all of them: https://github.com/nats-io/nats.rb (there's tls config etc)
|
32
33
|
},
|
33
34
|
}.freeze
|
@@ -36,10 +37,10 @@ module BPS
|
|
36
37
|
port = url.port&.to_s || '4222'
|
37
38
|
servers = CGI.unescape(url.host).split(',').map do |host|
|
38
39
|
addr = "nats://#{host}"
|
39
|
-
addr << ':' << port unless
|
40
|
+
addr << ':' << port unless /:\d+$/.match?(addr)
|
40
41
|
addr
|
41
42
|
end
|
42
|
-
opts = CGI.parse(url.query).transform_values {|v| v.size == 1 ? v[0] : v }
|
43
|
+
opts = CGI.parse(url.query || '').transform_values {|v| v.size == 1 ? v[0] : v }
|
43
44
|
cluster_id = opts.delete('cluster_id')
|
44
45
|
client_id = opts.delete('client_id')
|
45
46
|
[cluster_id, client_id, { nats: { servers: servers } }]
|
@@ -56,6 +57,14 @@ module BPS
|
|
56
57
|
def initialize(cluster_id, client_id, nats: {}, **opts)
|
57
58
|
super()
|
58
59
|
|
60
|
+
# handle TLS if CA file is provided:
|
61
|
+
if !nats[:tls] && nats[:tls_ca_file]
|
62
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
63
|
+
ctx.set_params
|
64
|
+
ctx.ca_file = nats.delete(:tls_ca_file)
|
65
|
+
nats[:tls] = ctx
|
66
|
+
end
|
67
|
+
|
59
68
|
@topics = {}
|
60
69
|
@client = ::STAN::Client.new
|
61
70
|
@client.connect(cluster_id, client_id, nats: nats, **opts.slice(*CLIENT_OPTS.keys))
|
data/spec/bps/stan_spec.rb
CHANGED
@@ -2,28 +2,29 @@ require 'bps/stan'
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
RSpec.describe 'STAN', stan: true do
|
5
|
-
context '
|
6
|
-
let(:publisher) {
|
5
|
+
context 'with addr resolving' do
|
6
|
+
let(:publisher) { instance_double('BPS::Publisher::STAN') }
|
7
|
+
|
7
8
|
before { allow(BPS::Publisher::STAN).to receive(:new).and_return(publisher) }
|
8
9
|
|
9
|
-
it '
|
10
|
-
|
10
|
+
it 'resolves simple URLs' do
|
11
|
+
allow(BPS::Publisher::STAN)
|
11
12
|
.to receive(:new)
|
12
13
|
.with('CLUSTER', 'CLIENT', nats: { servers: ['nats://test.host:4222'] })
|
13
14
|
.and_return(publisher)
|
14
15
|
BPS::Publisher.resolve(URI.parse('stan://test.host:4222?cluster_id=CLUSTER&client_id=CLIENT'))
|
15
16
|
end
|
16
17
|
|
17
|
-
it '
|
18
|
-
|
18
|
+
it 'resolves URLs with multiple hosts' do
|
19
|
+
allow(BPS::Publisher::STAN)
|
19
20
|
.to receive(:new)
|
20
21
|
.with('CLUSTER', 'CLIENT', nats: { servers: ['nats://foo.host:4222', 'nats://bar.host:4222'] })
|
21
22
|
.and_return(publisher)
|
22
23
|
BPS::Publisher.resolve(URI.parse('stan://foo.host,bar.host:4222?cluster_id=CLUSTER&client_id=CLIENT'))
|
23
24
|
end
|
24
25
|
|
25
|
-
it '
|
26
|
-
|
26
|
+
it 'resolves URLs with multiple hosts/ports' do
|
27
|
+
allow(BPS::Publisher::STAN)
|
27
28
|
.to receive(:new)
|
28
29
|
.with('CLUSTER', 'CLIENT', nats: { servers: ['nats://foo.host:4223', 'nats://bar.host:4222'] })
|
29
30
|
.and_return(publisher)
|
@@ -35,7 +36,7 @@ RSpec.describe 'STAN', stan: true do
|
|
35
36
|
let(:cluster_id) { 'test-cluster' } # this is a default cluster for https://hub.docker.com/_/nats-streaming
|
36
37
|
let(:client_id) { 'bps-test' }
|
37
38
|
|
38
|
-
let(:nats_servers) { ENV.fetch('
|
39
|
+
let(:nats_servers) { ENV.fetch('STAN_SERVERS', '127.0.0.1:4222').split(',') }
|
39
40
|
let(:nats_servers_with_scheme) { nats_servers.map {|s| "nats://#{s}" } }
|
40
41
|
|
41
42
|
let(:publisher_url) { "stan://#{CGI.escape(nats_servers.join(','))}/?cluster_id=#{cluster_id}&client_id=#{client_id}" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bps-stan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Black Square Media
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bps
|
@@ -16,26 +16,26 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nats-streaming
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.2.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.2.2
|
41
41
|
description: https://github.com/bsm/bps
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
|
-
rubygems_version: 3.1.
|
71
|
+
rubygems_version: 3.1.4
|
72
72
|
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: BPS adapter for nats-streaming
|