nats-pure 2.0.0 → 2.1.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/lib/nats/io/client.rb +14 -26
- data/lib/nats/io/js.rb +19 -4
- data/lib/nats/io/version.rb +1 -1
- data/lib/nats/nuid.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0d4251703ba9fd6a91f501686025e2f71e93dc7869f65984da7cd312361266
|
4
|
+
data.tar.gz: 411fdfd23878cf89b26c76e04b68c760e10aaef14f2a68fae19c69a8d1392990
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b88a713e2c1b6a515ac4f505cb6724c0059e72693d8d5c2ee61f3579d1b4b846408282e131864735dccc8b224e4a22933be91409d404fedadf0ec6c72051cf
|
7
|
+
data.tar.gz: 9ef88d1a391c2cfec91731aca2742382634c923384b801fce4ee9155418de39bd538f7aaafceb6ba2a1b40b57c6b7db4363ad4cf673d8ff3b5e87b5f74104789
|
data/lib/nats/io/client.rb
CHANGED
@@ -227,6 +227,7 @@ module NATS
|
|
227
227
|
opts[:pedantic] = false if opts[:pedantic].nil?
|
228
228
|
opts[:reconnect] = true if opts[:reconnect].nil?
|
229
229
|
opts[:old_style_request] = false if opts[:old_style_request].nil?
|
230
|
+
opts[:ignore_discovered_urls] = false if opts[:ignore_discovered_urls].nil?
|
230
231
|
opts[:reconnect_time_wait] = NATS::IO::RECONNECT_TIME_WAIT if opts[:reconnect_time_wait].nil?
|
231
232
|
opts[:max_reconnect_attempts] = NATS::IO::MAX_RECONNECT_ATTEMPTS if opts[:max_reconnect_attempts].nil?
|
232
233
|
opts[:ping_interval] = NATS::IO::DEFAULT_PING_INTERVAL if opts[:ping_interval].nil?
|
@@ -237,6 +238,7 @@ module NATS
|
|
237
238
|
opts[:pedantic] = ENV['NATS_PEDANTIC'].downcase == 'true' unless ENV['NATS_PEDANTIC'].nil?
|
238
239
|
opts[:reconnect] = ENV['NATS_RECONNECT'].downcase == 'true' unless ENV['NATS_RECONNECT'].nil?
|
239
240
|
opts[:reconnect_time_wait] = ENV['NATS_RECONNECT_TIME_WAIT'].to_i unless ENV['NATS_RECONNECT_TIME_WAIT'].nil?
|
241
|
+
opts[:ignore_discovered_urls] = ENV['NATS_IGNORE_DISCOVERED_URLS'].downcase == 'true' unless ENV['NATS_IGNORE_DISCOVERED_URLS'].nil?
|
240
242
|
opts[:max_reconnect_attempts] = ENV['NATS_MAX_RECONNECT_ATTEMPTS'].to_i unless ENV['NATS_MAX_RECONNECT_ATTEMPTS'].nil?
|
241
243
|
opts[:ping_interval] = ENV['NATS_PING_INTERVAL'].to_i unless ENV['NATS_PING_INTERVAL'].nil?
|
242
244
|
opts[:max_outstanding_pings] = ENV['NATS_MAX_OUTSTANDING_PINGS'].to_i unless ENV['NATS_MAX_OUTSTANDING_PINGS'].nil?
|
@@ -256,7 +258,7 @@ module NATS
|
|
256
258
|
end
|
257
259
|
@server_pool << {
|
258
260
|
:uri => nats_uri,
|
259
|
-
:hostname => nats_uri.
|
261
|
+
:hostname => nats_uri.hostname
|
260
262
|
}
|
261
263
|
end
|
262
264
|
|
@@ -807,17 +809,17 @@ module NATS
|
|
807
809
|
|
808
810
|
# Detect any announced server that we might not be aware of...
|
809
811
|
connect_urls = @server_info[:connect_urls]
|
810
|
-
if connect_urls
|
812
|
+
if !@options[:ignore_discovered_urls] && connect_urls
|
811
813
|
srvs = []
|
812
814
|
connect_urls.each do |url|
|
813
815
|
scheme = client_using_secure_connection? ? "tls" : "nats"
|
814
816
|
u = URI.parse("#{scheme}://#{url}")
|
815
817
|
|
816
818
|
# Skip in case it is the current server which we already know
|
817
|
-
next if @uri.
|
819
|
+
next if @uri.hostname == u.hostname && @uri.port == u.port
|
818
820
|
|
819
821
|
present = server_pool.detect do |srv|
|
820
|
-
srv[:uri].
|
822
|
+
srv[:uri].hostname == u.hostname && srv[:uri].port == u.port
|
821
823
|
end
|
822
824
|
|
823
825
|
if not present
|
@@ -832,7 +834,7 @@ module NATS
|
|
832
834
|
end
|
833
835
|
|
834
836
|
# NOTE: Auto discovery won't work here when TLS host verification is enabled.
|
835
|
-
srv = { :uri => u, :reconnect_attempts => 0, :discovered => true, :hostname => u.
|
837
|
+
srv = { :uri => u, :reconnect_attempts => 0, :discovered => true, :hostname => u.hostname }
|
836
838
|
srvs << srv
|
837
839
|
end
|
838
840
|
end
|
@@ -1758,34 +1760,20 @@ module NATS
|
|
1758
1760
|
end
|
1759
1761
|
|
1760
1762
|
def process_uri(uris)
|
1761
|
-
|
1762
|
-
uris.split(',').each do |uri|
|
1763
|
+
uris.split(',').map do |uri|
|
1763
1764
|
opts = {}
|
1764
1765
|
|
1765
1766
|
# Scheme
|
1766
|
-
if uri.include?("://")
|
1767
|
-
scheme, uri = uri.split("://")
|
1768
|
-
opts[:scheme] = scheme
|
1769
|
-
else
|
1770
|
-
opts[:scheme] = 'nats'
|
1771
|
-
end
|
1767
|
+
uri = "nats://#{uri}" if !uri.include?("://")
|
1772
1768
|
|
1773
|
-
|
1774
|
-
if uri.include?("@")
|
1775
|
-
userinfo, endpoint = uri.split("@")
|
1776
|
-
host, port = endpoint.split(":")
|
1777
|
-
opts[:userinfo] = userinfo
|
1778
|
-
else
|
1779
|
-
host, port = uri.split(":")
|
1780
|
-
end
|
1769
|
+
uri_object = URI(uri)
|
1781
1770
|
|
1782
1771
|
# Host and Port
|
1783
|
-
|
1784
|
-
|
1772
|
+
uri_object.hostname ||= "localhost"
|
1773
|
+
uri_object.port ||= DEFAULT_PORT
|
1785
1774
|
|
1786
|
-
|
1775
|
+
uri_object
|
1787
1776
|
end
|
1788
|
-
connect_uris
|
1789
1777
|
end
|
1790
1778
|
end
|
1791
1779
|
|
@@ -1834,7 +1822,7 @@ module NATS
|
|
1834
1822
|
end
|
1835
1823
|
|
1836
1824
|
def connect
|
1837
|
-
addrinfo = ::Socket.getaddrinfo(@uri.
|
1825
|
+
addrinfo = ::Socket.getaddrinfo(@uri.hostname, nil, ::Socket::AF_UNSPEC, ::Socket::SOCK_STREAM)
|
1838
1826
|
addrinfo.each_with_index do |ai, i|
|
1839
1827
|
begin
|
1840
1828
|
@socket = connect_addrinfo(ai, @uri.port, @connect_timeout)
|
data/lib/nats/io/js.rb
CHANGED
@@ -284,6 +284,7 @@ module NATS
|
|
284
284
|
end
|
285
285
|
stream = config[:name]
|
286
286
|
raise ArgumentError.new(":name is required to create streams") unless stream
|
287
|
+
raise ArgumentError.new("Spaces, tabs, period (.), greater than (>) or asterisk (*) are prohibited in stream names") if stream =~ /(\s|\.|\>|\*)/
|
287
288
|
req_subject = "#{@prefix}.STREAM.CREATE.#{stream}"
|
288
289
|
result = api_request(req_subject, config.to_json, params)
|
289
290
|
JetStream::API::StreamCreateResponse.new(result)
|
@@ -345,6 +346,7 @@ module NATS
|
|
345
346
|
stream_name: stream,
|
346
347
|
config: config
|
347
348
|
}
|
349
|
+
|
348
350
|
result = api_request(req_subject, req.to_json, params)
|
349
351
|
JetStream::API::ConsumerInfo.new(result).freeze
|
350
352
|
end
|
@@ -502,6 +504,7 @@ module NATS
|
|
502
504
|
synchronize do
|
503
505
|
unless @pending_queue.empty?
|
504
506
|
msg = @pending_queue.pop
|
507
|
+
@pending_size -= msg.data.size
|
505
508
|
# Check for a no msgs response status.
|
506
509
|
if JS.is_status_msg(msg)
|
507
510
|
case msg.header["Status"]
|
@@ -527,7 +530,12 @@ module NATS
|
|
527
530
|
# Wait for result of fetch or timeout.
|
528
531
|
synchronize { wait_for_msgs_cond.wait(timeout) }
|
529
532
|
|
530
|
-
|
533
|
+
unless @pending_queue.empty?
|
534
|
+
msg = @pending_queue.pop
|
535
|
+
@pending_size -= msg.data.size
|
536
|
+
|
537
|
+
msgs << msg
|
538
|
+
end
|
531
539
|
|
532
540
|
duration = MonotonicTime.since(t)
|
533
541
|
if duration > timeout
|
@@ -556,6 +564,7 @@ module NATS
|
|
556
564
|
if batch <= @pending_queue.size
|
557
565
|
batch.times do
|
558
566
|
msg = @pending_queue.pop
|
567
|
+
@pending_size -= msg.data.size
|
559
568
|
|
560
569
|
# Check for a no msgs response status.
|
561
570
|
if JS.is_status_msg(msg)
|
@@ -582,10 +591,15 @@ module NATS
|
|
582
591
|
# Not receiving even one is a timeout.
|
583
592
|
start_time = MonotonicTime.now
|
584
593
|
msg = nil
|
585
|
-
|
594
|
+
|
595
|
+
synchronize do
|
586
596
|
wait_for_msgs_cond.wait(timeout)
|
587
|
-
|
588
|
-
|
597
|
+
|
598
|
+
unless @pending_queue.empty?
|
599
|
+
msg = @pending_queue.pop
|
600
|
+
@pending_size -= msg.data.size
|
601
|
+
end
|
602
|
+
end
|
589
603
|
|
590
604
|
# Check if the first message was a response saying that
|
591
605
|
# there are no messages.
|
@@ -630,6 +644,7 @@ module NATS
|
|
630
644
|
end
|
631
645
|
else
|
632
646
|
msg = @pending_queue.pop
|
647
|
+
@pending_size -= msg.data.size
|
633
648
|
|
634
649
|
if JS.is_status_msg(msg)
|
635
650
|
case msg.header[JS::Header::Status]
|
data/lib/nats/io/version.rb
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
module NATS
|
16
16
|
module IO
|
17
17
|
# VERSION is the version of the client announced on CONNECT to the server.
|
18
|
-
VERSION = "2.
|
18
|
+
VERSION = "2.1.0".freeze
|
19
19
|
|
20
20
|
# LANG is the lang runtime of the client announced on CONNECT to the server.
|
21
21
|
LANG = "#{RUBY_ENGINE}#{RUBY_VERSION}".freeze
|
data/lib/nats/nuid.rb
CHANGED
@@ -15,7 +15,7 @@ require 'securerandom'
|
|
15
15
|
|
16
16
|
module NATS
|
17
17
|
class NUID
|
18
|
-
DIGITS
|
18
|
+
DIGITS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
|
19
19
|
BASE = 62
|
20
20
|
PREFIX_LENGTH = 12
|
21
21
|
SEQ_LENGTH = 10
|
@@ -25,6 +25,8 @@ module NATS
|
|
25
25
|
MAX_INC = 333
|
26
26
|
INC = MAX_INC - MIN_INC
|
27
27
|
|
28
|
+
Ractor.make_shareable(DIGITS) if defined?(Ractor)
|
29
|
+
|
28
30
|
def initialize
|
29
31
|
@prand = Random.new
|
30
32
|
@seq = @prand.rand(MAX_SEQ)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nats-pure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Waldemar Quevedo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: NATS is an open-source, high-performance, lightweight cloud messaging
|
14
14
|
system.
|
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|
51
|
-
rubygems_version: 3.
|
51
|
+
rubygems_version: 3.3.3
|
52
52
|
signing_key:
|
53
53
|
specification_version: 4
|
54
54
|
summary: NATS is an open-source, high-performance, lightweight cloud messaging system.
|