nats-pure 2.0.0.pre.rc2 → 2.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d16ee062f4cee20fd50abb3d9f78a2e2aa3c92648717ae4e6906e93255920d89
4
- data.tar.gz: d4fa9ee8eb06ca8379493de124d7c125dd15a929550316c943be9bd2ae8d8743
3
+ metadata.gz: 154ce22f3fa8a4256d0a0bc45fd3356286956c6f774f8332e5892c0be6af45d8
4
+ data.tar.gz: de9022e08deff77f48c3ef8dd4e538d307ddc44eea57ac884b862893df354750
5
5
  SHA512:
6
- metadata.gz: ec7aa2c9dd3ce098d7ebdd083ecabe581ebe22302d5cd452feb4e718bebf2b453c455ad6786a0f9bfb7a34f49e348ba9829184521a7f161fbd9ba96df6f39383
7
- data.tar.gz: 8667b8373d87a4f905723f881991645c48a731bafd98a6a533316857fa6a6e56e0493edb753a4b9b01be62fa52b6a82c2a32269e337f4f82e105f48ed8602100
6
+ metadata.gz: 92f10f12b63062c756a5b041e1e2f604d23f7b372d9c3a22425d91e0cb2e6d0ff09f805722cdbe30eb6599566ec3715006127a144c2e9df92724dd307dc2d8b7
7
+ data.tar.gz: 3ec16e14c8ecfc15d9d8f00c2af4413c7ca35f372ac5ca38d7577df9629ca0b22a7885b0abd7c9665e9004b8c1592823ce23bb37285b3609a320c086efc98be9
@@ -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.host
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.host == u.host && @uri.port == u.port
819
+ next if @uri.hostname == u.hostname && @uri.port == u.port
818
820
 
819
821
  present = server_pool.detect do |srv|
820
- srv[:uri].host == u.host && srv[:uri].port == u.port
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.host }
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
- connect_uris = []
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
- # UserInfo
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
- opts[:host] = host || "localhost"
1784
- opts[:port] = port || DEFAULT_PORT
1772
+ uri_object.hostname ||= "localhost"
1773
+ uri_object.port ||= DEFAULT_PORT
1785
1774
 
1786
- connect_uris << URI::Generic.build(opts)
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.host, nil, ::Socket::AF_UNSPEC, ::Socket::SOCK_STREAM)
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
@@ -118,6 +118,7 @@ module NATS
118
118
  manual_ack = params[:manual_ack]
119
119
  idle_heartbeat = params[:idle_heartbeat]
120
120
  flow_control = params[:flow_control]
121
+ config = params[:config]
121
122
 
122
123
  if queue
123
124
  if durable and durable != queue
@@ -284,6 +285,7 @@ module NATS
284
285
  end
285
286
  stream = config[:name]
286
287
  raise ArgumentError.new(":name is required to create streams") unless stream
288
+ raise ArgumentError.new("Spaces, tabs, period (.), greater than (>) or asterisk (*) are prohibited in stream names") if stream =~ /(\s|\.|\>|\*)/
287
289
  req_subject = "#{@prefix}.STREAM.CREATE.#{stream}"
288
290
  result = api_request(req_subject, config.to_json, params)
289
291
  JetStream::API::StreamCreateResponse.new(result)
@@ -345,6 +347,7 @@ module NATS
345
347
  stream_name: stream,
346
348
  config: config
347
349
  }
350
+
348
351
  result = api_request(req_subject, req.to_json, params)
349
352
  JetStream::API::ConsumerInfo.new(result).freeze
350
353
  end
@@ -502,11 +505,14 @@ module NATS
502
505
  synchronize do
503
506
  unless @pending_queue.empty?
504
507
  msg = @pending_queue.pop
508
+ @pending_size -= msg.data.size
505
509
  # Check for a no msgs response status.
506
510
  if JS.is_status_msg(msg)
507
511
  case msg.header["Status"]
508
512
  when JS::Status::NoMsgs
509
513
  msg = nil
514
+ when JS::Status::RequestTimeout
515
+ # Skip
510
516
  else
511
517
  raise JS.from_msg(msg)
512
518
  end
@@ -525,7 +531,12 @@ module NATS
525
531
  # Wait for result of fetch or timeout.
526
532
  synchronize { wait_for_msgs_cond.wait(timeout) }
527
533
 
528
- msgs << @pending_queue.pop unless @pending_queue.empty?
534
+ unless @pending_queue.empty?
535
+ msg = @pending_queue.pop
536
+ @pending_size -= msg.data.size
537
+
538
+ msgs << msg
539
+ end
529
540
 
530
541
  duration = MonotonicTime.since(t)
531
542
  if duration > timeout
@@ -535,7 +546,13 @@ module NATS
535
546
  # Should have received at least a message at this point,
536
547
  # if that is not the case then error already.
537
548
  if JS.is_status_msg(msgs.first)
538
- raise JS.from_msg(msgs.first)
549
+ msg = msgs.first
550
+ case msg.header[JS::Header::Status]
551
+ when JS::Status::RequestTimeout
552
+ raise NATS::Timeout.new("nats: fetch request timeout")
553
+ else
554
+ raise JS.from_msg(msgs.first)
555
+ end
539
556
  end
540
557
  end
541
558
  when batch > 1
@@ -546,7 +563,23 @@ module NATS
546
563
  # Check if there already enough in the pending buffer.
547
564
  synchronize do
548
565
  if batch <= @pending_queue.size
549
- batch.times { msgs << @pending_queue.pop }
566
+ batch.times do
567
+ msg = @pending_queue.pop
568
+ @pending_size -= msg.data.size
569
+
570
+ # Check for a no msgs response status.
571
+ if JS.is_status_msg(msg)
572
+ case msg.header[JS::Header::Status]
573
+ when JS::Status::NoMsgs, JS::Status::RequestTimeout
574
+ # Skip these
575
+ next
576
+ else
577
+ raise JS.from_msg(msg)
578
+ end
579
+ else
580
+ msgs << msg
581
+ end
582
+ end
550
583
 
551
584
  return msgs
552
585
  end
@@ -559,10 +592,15 @@ module NATS
559
592
  # Not receiving even one is a timeout.
560
593
  start_time = MonotonicTime.now
561
594
  msg = nil
562
- synchronize {
595
+
596
+ synchronize do
563
597
  wait_for_msgs_cond.wait(timeout)
564
- msg = @pending_queue.pop unless @pending_queue.empty?
565
- }
598
+
599
+ unless @pending_queue.empty?
600
+ msg = @pending_queue.pop
601
+ @pending_size -= msg.data.size
602
+ end
603
+ end
566
604
 
567
605
  # Check if the first message was a response saying that
568
606
  # there are no messages.
@@ -574,11 +612,13 @@ module NATS
574
612
  next_req.delete(:no_wait)
575
613
 
576
614
  @nc.publish(@jsi.nms, JS.next_req_to_json(next_req), @subject)
615
+ when JS::Status::RequestTimeout
616
+ raise NATS::Timeout.new("nats: fetch request timeout")
577
617
  else
578
618
  raise JS.from_msg(msg)
579
619
  end
580
620
  else
581
- msgs << msg
621
+ msgs << msg unless msg.nil?
582
622
  end
583
623
 
584
624
  # Check if have not received yet a single message.
@@ -605,23 +645,27 @@ module NATS
605
645
  end
606
646
  else
607
647
  msg = @pending_queue.pop
648
+ @pending_size -= msg.data.size
608
649
 
609
650
  if JS.is_status_msg(msg)
610
- case msg.header["Status"]
651
+ case msg.header[JS::Header::Status]
611
652
  when JS::Status::NoMsgs, JS::Status::RequestTimeout
612
653
  duration = MonotonicTime.since(start_time)
613
654
 
614
- # Do not time out if we received at least some messages.
615
- if msgs.empty? && @pending_queue.empty? and duration > timeout
616
- raise NATS::Timeout.new("nats: fetch timeout")
655
+ if duration > timeout
656
+ # Only received a subset of the messages.
657
+ if !msgs.empty?
658
+ return msgs
659
+ else
660
+ raise NATS::Timeout.new("nats: fetch timeout")
661
+ end
617
662
  end
618
-
619
- # Likely only received a subset of the messages.
620
- return msgs
621
663
  else
622
664
  raise JS.from_msg(msg)
623
665
  end
666
+
624
667
  else
668
+ # Add to the set of messages that will be returned.
625
669
  msgs << msg
626
670
  needed -= 1
627
671
  end
@@ -1092,12 +1136,24 @@ module NATS
1092
1136
  # @return [Integer]
1093
1137
  # @!attribute max_ack_pending
1094
1138
  # @return [Integer]
1095
- ConsumerConfig = Struct.new(:durable_name, :description, :deliver_subject,
1096
- :deliver_group, :deliver_policy, :opt_start_seq,
1097
- :opt_start_time, :ack_policy, :ack_wait, :max_deliver,
1139
+ ConsumerConfig = Struct.new(:durable_name, :description,
1140
+ :deliver_policy, :opt_start_seq, :opt_start_time,
1141
+ :ack_policy, :ack_wait, :max_deliver, :backoff,
1098
1142
  :filter_subject, :replay_policy, :rate_limit_bps,
1099
1143
  :sample_freq, :max_waiting, :max_ack_pending,
1100
1144
  :flow_control, :idle_heartbeat, :headers_only,
1145
+
1146
+ # Pull based options
1147
+ :max_batch, :max_expires,
1148
+ # Push based consumers
1149
+ :deliver_subject, :deliver_group,
1150
+ # Ephemeral inactivity threshold
1151
+ :inactive_threshold,
1152
+ # Generally inherited by parent stream and other markers,
1153
+ # now can be configured directly.
1154
+ :num_replicas,
1155
+ # Force memory storage
1156
+ :memory_storage,
1101
1157
  keyword_init: true) do
1102
1158
  def initialize(opts={})
1103
1159
  # Filter unrecognized fields just in case.
@@ -1151,10 +1207,11 @@ module NATS
1151
1207
  # @return [Integer]
1152
1208
  # @!attribute duplicate_window
1153
1209
  # @return [Integer]
1154
- StreamConfig = Struct.new(:name, :subjects, :retention, :max_consumers,
1155
- :max_msgs, :max_bytes, :max_age,
1210
+ StreamConfig = Struct.new(:name, :description, :subjects, :retention, :max_consumers,
1211
+ :max_msgs, :max_bytes, :discard, :max_age,
1156
1212
  :max_msgs_per_subject, :max_msg_size,
1157
- :discard, :storage, :num_replicas, :duplicate_window,
1213
+ :storage, :num_replicas, :no_ack, :duplicate_window,
1214
+ :placement, :allow_direct,
1158
1215
  keyword_init: true) do
1159
1216
  def initialize(opts={})
1160
1217
  # Filter unrecognized fields just in case.
@@ -1,4 +1,4 @@
1
- # Copyright 2016-2021 The NATS Authors
1
+ # Copyright 2016-2022 The NATS Authors
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -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.0.0-rc2".freeze
18
+ VERSION = "2.1.2".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 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
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.0.0.pre.rc2
4
+ version: 2.1.2
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-01-26 00:00:00.000000000 Z
11
+ date: 2022-07-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: NATS is an open-source, high-performance, lightweight cloud messaging
14
14
  system.
@@ -44,11 +44,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.3.1
49
+ version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.2.22
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.