nats-pure 0.7.2 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -0
  3. data/README.md +251 -0
  4. data/lib/nats/client.rb +16 -0
  5. data/lib/nats/io/client.rb +1559 -1277
  6. data/lib/nats/io/errors.rb +74 -0
  7. data/lib/nats/io/jetstream/api.rb +309 -0
  8. data/lib/nats/io/jetstream/errors.rb +104 -0
  9. data/lib/nats/io/jetstream/js/config.rb +26 -0
  10. data/lib/nats/io/jetstream/js/header.rb +31 -0
  11. data/lib/nats/io/jetstream/js/status.rb +27 -0
  12. data/lib/nats/io/jetstream/js/sub.rb +30 -0
  13. data/lib/nats/io/jetstream/js.rb +93 -0
  14. data/lib/nats/io/jetstream/manager.rb +303 -0
  15. data/lib/nats/io/jetstream/msg/ack.rb +57 -0
  16. data/lib/nats/io/jetstream/msg/ack_methods.rb +111 -0
  17. data/lib/nats/io/jetstream/msg/metadata.rb +37 -0
  18. data/lib/nats/io/jetstream/msg.rb +26 -0
  19. data/lib/nats/io/jetstream/pull_subscription.rb +260 -0
  20. data/lib/nats/io/jetstream/push_subscription.rb +42 -0
  21. data/lib/nats/io/jetstream.rb +344 -0
  22. data/lib/nats/io/kv/api.rb +39 -0
  23. data/lib/nats/io/kv/bucket_status.rb +38 -0
  24. data/lib/nats/io/kv/errors.rb +60 -0
  25. data/lib/nats/io/kv/manager.rb +89 -0
  26. data/lib/nats/io/kv.rb +178 -0
  27. data/lib/nats/io/msg.rb +58 -0
  28. data/lib/nats/io/parser.rb +7 -7
  29. data/lib/nats/io/rails.rb +29 -0
  30. data/lib/nats/io/subscription.rb +157 -0
  31. data/lib/nats/io/version.rb +8 -4
  32. data/lib/nats/io/websocket.rb +75 -0
  33. data/lib/nats/nuid.rb +3 -1
  34. data/lib/nats.rb +39 -0
  35. data/sig/nats/io/client.rbs +304 -0
  36. data/sig/nats/io/errors.rbs +54 -0
  37. data/sig/nats/io/jetstream/api.rbs +35 -0
  38. data/sig/nats/io/jetstream/errors.rbs +54 -0
  39. data/sig/nats/io/jetstream/js/config.rbs +11 -0
  40. data/sig/nats/io/jetstream/js/header.rbs +17 -0
  41. data/sig/nats/io/jetstream/js/status.rbs +13 -0
  42. data/sig/nats/io/jetstream/js/sub.rbs +14 -0
  43. data/sig/nats/io/jetstream/js.rbs +27 -0
  44. data/sig/nats/io/jetstream/manager.rbs +33 -0
  45. data/sig/nats/io/jetstream/msg/ack.rbs +35 -0
  46. data/sig/nats/io/jetstream/msg/ack_methods.rbs +25 -0
  47. data/sig/nats/io/jetstream/msg/metadata.rbs +15 -0
  48. data/sig/nats/io/jetstream/msg.rbs +6 -0
  49. data/sig/nats/io/jetstream/pull_subscription.rbs +14 -0
  50. data/sig/nats/io/jetstream/push_subscription.rbs +7 -0
  51. data/sig/nats/io/jetstream.rbs +15 -0
  52. data/sig/nats/io/kv/api.rbs +8 -0
  53. data/sig/nats/io/kv/bucket_status.rbs +17 -0
  54. data/sig/nats/io/kv/errors.rbs +30 -0
  55. data/sig/nats/io/kv/manager.rbs +11 -0
  56. data/sig/nats/io/kv.rbs +39 -0
  57. data/sig/nats/io/msg.rbs +14 -0
  58. data/sig/nats/io/parser.rbs +32 -0
  59. data/sig/nats/io/subscription.rbs +33 -0
  60. data/sig/nats/io/version.rbs +9 -0
  61. data/sig/nats/nuid.rbs +32 -0
  62. metadata +74 -4
@@ -0,0 +1,75 @@
1
+ begin
2
+ require 'websocket'
3
+ rescue LoadError
4
+ raise LoadError, "Please add `websocket` gem to your Gemfile to connect to NATS via WebSocket."
5
+ end
6
+
7
+ module NATS
8
+ module IO
9
+ # WebSocket to connect to NATS via WebSocket and automatically decode and encode frames.
10
+
11
+ # @see https://docs.nats.io/running-a-nats-service/configuration/websocket
12
+
13
+ class WebSocket < Socket
14
+ class HandshakeError < RuntimeError; end
15
+
16
+ attr_accessor :socket
17
+
18
+ def initialize(options={})
19
+ super
20
+ end
21
+
22
+ def connect
23
+ super
24
+
25
+ setup_tls! if @uri.scheme == "wss" # WebSocket connection must be made over TLS from the beginning
26
+
27
+ @handshake = ::WebSocket::Handshake::Client.new url: @uri.to_s
28
+ @frame = ::WebSocket::Frame::Incoming::Client.new
29
+ @handshaked = false
30
+
31
+ @socket.write @handshake.to_s
32
+
33
+ until @handshaked
34
+ @handshake << method(:read).super_method.call(MAX_SOCKET_READ_BYTES)
35
+ if @handshake.finished?
36
+ @handshaked = true
37
+ end
38
+ end
39
+ end
40
+
41
+ def setup_tls!
42
+ return if @socket.is_a? OpenSSL::SSL::SSLSocket
43
+
44
+ super
45
+ end
46
+
47
+ def read(max_bytes=MAX_SOCKET_READ_BYTES, deadline=nil)
48
+ data = super
49
+ @frame << data
50
+ result = []
51
+ while msg = @frame.next
52
+ result << msg
53
+ end
54
+ result.join
55
+ end
56
+
57
+ def read_line(deadline=nil)
58
+ data = super
59
+ @frame << data
60
+ result = []
61
+ while msg = @frame.next
62
+ result << msg
63
+ end
64
+ result.join
65
+ end
66
+
67
+ def write(data, deadline=nil)
68
+ raise HandshakeError, "Attempted to write to socket while WebSocket handshake is in progress" unless @handshaked
69
+
70
+ frame = ::WebSocket::Frame::Outgoing::Client.new(data: data, type: :binary, version: @handshake.version)
71
+ super frame.to_s
72
+ end
73
+ end
74
+ end
75
+ end
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)
data/lib/nats.rb ADDED
@@ -0,0 +1,39 @@
1
+ # Copyright 2021 The NATS Authors
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ require 'nats/io/client'
16
+ require 'nats/nuid'
17
+
18
+ # A thread safe Ruby client for the NATS messaging system (https://nats.io).
19
+ #
20
+ # @example Service example
21
+ # nc = NATS.connect("demo.nats.io")
22
+ # nc.subscribe("foo") do |msg|
23
+ # msg.respond("Hello World")
24
+ # end
25
+ #
26
+ # resp = nc.request("foo")
27
+ # puts "Received: #{msg.data}"
28
+ #
29
+ #
30
+ # @example Stream example
31
+ # nc = NATS.connect("demo.nats.io")
32
+ # sub = nc.subscribe("foo")
33
+ #
34
+ # nc.publish("foo")
35
+ # msg = sub.next_msg
36
+ # puts "Received: #{msg.data}"
37
+ #
38
+ module NATS
39
+ end
@@ -0,0 +1,304 @@
1
+ module NATS
2
+ # class << self
3
+ def self.connect: (String?, Hash[Symbol, untyped]) -> NATS::Client
4
+ # end class << self
5
+
6
+ module Status
7
+ DISCONNECTED: Integer
8
+ CONNECTED: Integer
9
+ CLOSED: Integer
10
+ RECONNECTING: Integer
11
+ CONNECTING: Integer
12
+ DRAINING_SUBS: Integer
13
+ DRAINING_PUBS: Integer
14
+ end
15
+
16
+ class Client
17
+ include MonitorMixin
18
+ include Status
19
+
20
+ attr_reader status: Integer
21
+ attr_reader server_info: Hash[Symbol, untyped]
22
+ attr_reader server_pool: Array[untyped]
23
+ attr_reader options: Hash[Symbol, untyped]?
24
+ attr_reader connected_server: String?
25
+ attr_reader stats: Hash[Symbol, Integer]
26
+ attr_reader uri: String?
27
+ attr_reader subscription_executor: Concurrent::ThreadPoolExecutor?
28
+ attr_reader reloader: Proc
29
+
30
+ DEFAULT_PORT: Hash[Symbol, Integer]
31
+ DEFAULT_URI: String
32
+
33
+ CR_LF: '\r\n'
34
+ CR_LF_SIZE: Integer
35
+
36
+ PING_REQUEST: String
37
+ PONG_RESPONSE: String
38
+
39
+ NATS_HDR_LINE: String
40
+ STATUS_MSG_LEN: 3
41
+ STATUS_HDR: 'Status'
42
+ DESC_HDR: 'Description'
43
+ NATS_HDR_LINE_SIZE: Integer
44
+
45
+ SUB_OP: 'SUB'
46
+ EMPTY_MSG: ''
47
+
48
+ INSTANCES: ObjectSpace::WeakMap
49
+
50
+ @options: Hash[Symbol, untyped]
51
+
52
+ @io: NATS::IO::Socket?
53
+
54
+ @flush_queue: Thread::SizedQueue?
55
+ @pending_queue: Thread::SizedQueue?
56
+
57
+ @parser: NATS::Protocol::Parser
58
+
59
+ @flusher_thread: Thread?
60
+ @read_loop_thread: Thread?
61
+ @ping_interval_thread: Thread?
62
+ @subscription_executor: Concurrent::ThreadPoolExecutor?
63
+
64
+ @subs: Hash[Symbol, untyped]
65
+ @ssid: Integer
66
+
67
+ @pings_outstanding: Integer
68
+ @pongs_received: Integer
69
+ @pongs: Array[MonitorMixin::ConditionVariable]
70
+
71
+ @pending_size: Integer
72
+
73
+ @last_err: untyped
74
+
75
+ @err_cb: Proc
76
+ @close_cp: Proc
77
+ @disconnect_cb: Proc
78
+ @reconnect_cb: Proc
79
+
80
+ @tls: bool?
81
+
82
+ @hostname: String?
83
+ @single_url_connect_used: bool
84
+
85
+ @connect_called: bool
86
+
87
+ @resp_sub: NATS::Subscription?
88
+ @resp_map: Hash[String | Symbol, untyped]?
89
+ @resp_sub_prefix: String?
90
+ @nuid: NATS::NUID
91
+
92
+ @user_credentials: String?
93
+ @nkeys_seed: String?
94
+ @user_nkey_cb: Proc?
95
+ @user_jwt_cb: Proc?
96
+ @signature_cb: Proc?
97
+
98
+ @auth_token: String?
99
+
100
+ @inbox_prefix: String
101
+
102
+ @drain_t: Thread?
103
+
104
+ @reloader: Proc
105
+
106
+ def self.default_reloader: -> Proc
107
+
108
+ def connect: ((String | Hash[Symbol, untyped])?, Hash[Symbol, untyped]) -> self
109
+
110
+ def publish: (String, String, String?, **Hash[Symbol, untyped]) -> void
111
+
112
+ def publish_msg: (NATS::Msg) -> void
113
+
114
+ def subscribe: (String, Hash[Symbol, untyped]) ?{ (?(NATS::Msg | String), ?String, ?String, ?Hash[Symbol, untyped]) -> void } -> NATS::Subscription
115
+
116
+ def request: (String, ?String, **Hash[Symbol, untyped]) ?{ (?(NATS::Msg | String), ?String, ?String, ?Hash[Symbol, untyped]) -> void } -> NATS::Msg
117
+
118
+ def request_msg: (NATS::Msg, **Hash[Symbol, untyped]) -> NATS::Msg
119
+
120
+ def old_request: (String, ?String, **Hash[Symbol, untyped]) ?{ (?(NATS::Msg | String), ?String, ?String, ?Hash[Symbol, untyped]) -> void } -> NATS::Msg
121
+
122
+ def flush: (?Integer) -> void
123
+
124
+ alias servers server_pool
125
+
126
+ def discovered_servers: () -> Array[String]
127
+
128
+ def close: () -> void
129
+
130
+ def new_inbox: () -> String
131
+
132
+ def connected?: () -> bool
133
+
134
+ def connecting?: () -> bool
135
+
136
+ def reconnecting?: () -> bool
137
+
138
+ def closed?: () -> bool
139
+
140
+ def draining?: () -> bool
141
+
142
+ def on_error: () { (?self, ?untyped, ?NATS::Subscription) -> void } -> void
143
+
144
+ def on_disconnect: () { (?untyped) -> void } -> void
145
+
146
+ def on_reconnect: () { () -> void } -> void
147
+
148
+ def on_close: () { () -> void } -> void
149
+
150
+ def last_error: () -> untyped
151
+
152
+ def drain: () -> void
153
+
154
+ def jetstream: (**Hash[Symbol, untyped]) -> NATS::JetStream
155
+ alias JetStream jetstream
156
+ alias jsm jetstream
157
+
158
+ private
159
+
160
+ def validate_settings!: () -> void
161
+
162
+ def process_info: (String) -> Hash[Symbol, untyped]
163
+
164
+ def process_hdr: (String) -> Hash[String, untyped]?
165
+
166
+ def process_pong: () -> void
167
+
168
+ def process_ping: () -> void
169
+
170
+ def process_err: (String) -> void
171
+
172
+ def process_msg: (String, String, String, String, String) -> void
173
+
174
+ def select_next_error: () -> untyped
175
+
176
+ def server_using_secure_connection?: () -> bool
177
+
178
+ def client_using_secure_connection?: () -> bool
179
+
180
+ def single_url_connect_used?: () -> bool
181
+
182
+ def send_command: (String) -> void
183
+
184
+ def unsubscribe: (NATS::Subscription, Integer?) -> void
185
+
186
+ def drain_sub: (NATS::Subscription) -> void
187
+
188
+ def do_drain: () -> void
189
+
190
+ def send_flush_queue: (Symbol) -> void
191
+
192
+ def delete_sid: (Symbol) -> void
193
+
194
+ def err_cb_call: (self, untyped, NATS::Subscription) -> void
195
+
196
+ def auth_connection?: () -> bool
197
+
198
+ def connect_command: () -> String
199
+
200
+ def process_op_error: (untyped) -> void
201
+
202
+ def read_loop: () -> void
203
+
204
+ def flusher_loop: () -> void
205
+
206
+ def force_flush!: () -> void
207
+
208
+ def ping_interval_loop: () -> void
209
+
210
+ def process_connect_init: () -> void
211
+
212
+ def attempt_reconnect: () -> void
213
+
214
+ def close_connection: (Integer, bool) -> void
215
+
216
+ def start_threads!: () -> void
217
+
218
+ def start_resp_mux_sub!: () -> void
219
+
220
+ def can_reuse_server?: (Hash[Symbol, untyped]) -> bool
221
+
222
+ def should_delay_connect?: () -> bool
223
+
224
+ def should_not_reconnect?: () -> bool
225
+
226
+ def should_reconnect?: () -> bool
227
+
228
+ def create_socket: () -> NATS::IO::Socket
229
+
230
+ def setup_nkeys_connect: () -> void
231
+
232
+ def signature_cb_for_nkey_file: (String) -> Proc
233
+
234
+ def nkey_cb_for_nkey_file: (String) -> Proc
235
+
236
+ def jwt_cb_for_creds_file: (String) -> Proc
237
+
238
+ def signature_cb_for_creds_file: (String) -> Proc
239
+
240
+ def process_uri: (String) -> Array[URI::Generic]
241
+ end
242
+
243
+ module IO
244
+ include Status
245
+
246
+ Client: NATS::Client
247
+
248
+ MAX_RECONNECT_ATTEMPTS: 10
249
+ RECONNECT_TIME_WAIT: 2
250
+
251
+ MAX_PENDING_SIZE: 32768
252
+
253
+ MAX_FLUSH_KICK_SIZE: 1024
254
+
255
+ MAX_SOCKET_READ_BYTES: 32768
256
+
257
+ DEFAULT_PING_INTERVAL: 120
258
+ DEFAULT_PING_MAX: 2
259
+
260
+ DEFAULT_CONNECT_TIMEOUT: 2
261
+ DEFAULT_READ_WRITE_TIMEOUT: 2
262
+ DEFAULT_DRAIN_TIMEOUT: 30
263
+
264
+ DEFAULT_SUB_PENDING_MSGS_LIMIT: 65536
265
+ DEFAULT_SUB_PENDING_BYTES_LIMIT: Integer
266
+
267
+ class Socket
268
+ attr_accessor socket: ::Socket?
269
+
270
+ @uri: URI::Generic
271
+ @connect_timeout: Numeric
272
+ @write_timeout: Numeric
273
+ @read_timeout: Numeric
274
+
275
+ def connect: () -> void
276
+
277
+ def read_line: (Numeric?) -> untyped
278
+
279
+ def read: (Integer, Numeric?) -> untyped
280
+
281
+ def write: (String, Numeric?) -> void
282
+
283
+ def close: () -> void
284
+
285
+ def closed?: () -> bool
286
+
287
+ private
288
+
289
+ def connect_addrinfo: (String | Integer, Integer, Numeric) -> ::Socket
290
+ end
291
+ end
292
+
293
+ NANOSECONDS: 1_000_000_000
294
+
295
+ class MonotonicTime
296
+ # class << self
297
+ def self.now: () -> Float
298
+
299
+ def self.with_nats_timeout: (Float) -> Float
300
+
301
+ def self.since: (Float) -> Float
302
+ # end class << self
303
+ end
304
+ end
@@ -0,0 +1,54 @@
1
+ module NATS
2
+ module IO
3
+ class Error < StandardError
4
+ end
5
+
6
+ class ServerError < NATS::IO::Error
7
+ end
8
+
9
+ class ClientError < NATS::IO::Error
10
+ end
11
+
12
+ class ConnectError < NATS::IO::Error
13
+ end
14
+
15
+ class AuthError < NATS::IO::ConnectError
16
+ end
17
+
18
+ class NoServersError < NATS::IO::ConnectError
19
+ end
20
+
21
+ class NoRespondersError < NATS::IO::ConnectError
22
+ end
23
+
24
+ class StaleConnectionError < NATS::IO::Error
25
+ end
26
+
27
+ class Timeout < NATS::IO::Error
28
+ end
29
+
30
+ class SocketTimeoutError < NATS::IO::Timeout
31
+ end
32
+
33
+ class BadSubject < NATS::IO::Error
34
+ end
35
+
36
+ class BadSubscription < NATS::IO::Error
37
+ end
38
+
39
+ class SlowConsumer < NATS::IO::Error
40
+ end
41
+
42
+ class ConnectionDrainingError < NATS::IO::Error
43
+ end
44
+
45
+ class DrainTimeoutError < NATS::IO::Error
46
+ end
47
+ end
48
+
49
+ class Timeout < NATS::IO::Timeout
50
+ end
51
+
52
+ class Error < NATS::IO::Error
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ module NATS
2
+ class JetStream
3
+ module API
4
+ class Error < NATS::JetStream::Error::APIError
5
+ end
6
+
7
+ class SequenceInfo < Struct[Integer]
8
+ end
9
+
10
+ class ConsumerInfo < Struct[String | NATS::JetStream::API::ConsumerConfig | NATS::JetStream::API::SequenceInfo | Integer | Hash[Symbol, untyped]]
11
+ end
12
+
13
+ class ConsumerConfig < Struct[String | Integer]
14
+ def to_json: (*Hash[untyped, untyped]) -> String
15
+ end
16
+
17
+ class StreamConfig < Struct[String | Hash[Symbol, untyped] | NATS::JetStream::API::StreamState | bool | Integer]
18
+ def to_json: (*Hash[untyped, untyped]) -> String
19
+ end
20
+
21
+ class StreamInfo < Struct[String | Hash[Symbol, untyped]]
22
+ end
23
+
24
+ class StreamState < Struct[Integer]
25
+ end
26
+
27
+ class StreamCreateResponse < Struct[String | NATS::JetStream::API::StreamConfig | NATS::JetStream::API::StreamState | bool]
28
+ end
29
+
30
+ class RawStreamMsg < Struct[String | Integer | Hash[Symbol, untyped]]
31
+ def sequence: () -> Integer
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,54 @@
1
+ module NATS
2
+ class JetStream
3
+ class Error < NATS::IO::Error
4
+ class NoStreamResponse < NATS::JetStream::Error
5
+ end
6
+
7
+ class InvalidDurableName < NATS::JetStream::Error
8
+ end
9
+
10
+ class InvalidJSAck < NATS::JetStream::Error
11
+ end
12
+
13
+ class MsgAlreadyAckd < NATS::JetStream::Error
14
+ end
15
+
16
+ class NotJSMessage < NATS::JetStream::Error
17
+ end
18
+
19
+ class InvalidStreamName < NATS::JetStream::Error
20
+ end
21
+
22
+ class InvalidConsumerName < NATS::JetStream::Error
23
+ end
24
+
25
+ class APIError < NATS::JetStream::Error
26
+ attr_reader code: Integer
27
+ attr_reader err_code: Integer
28
+ attr_reader description: String
29
+ attr_reader stream: String
30
+ attr_reader seq: Integer
31
+
32
+ def initialize: (Hash[Symbol, untyped]) -> void
33
+ end
34
+
35
+ class ServiceUnavailable < NATS::JetStream::Error::APIError
36
+ end
37
+
38
+ class ServerError < NATS::JetStream::Error::APIError
39
+ end
40
+
41
+ class NotFound < NATS::JetStream::Error::APIError
42
+ end
43
+
44
+ class StreamNotFound < NATS::JetStream::Error::NotFound
45
+ end
46
+
47
+ class ConsumerNotFound < NATS::JetStream::Error::NotFound
48
+ end
49
+
50
+ class BadRequest < NATS::JetStream::Error::APIError
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ module Config
5
+ AckExplicit: 'explicit'
6
+ AckAll: 'all'
7
+ AckNone: 'none'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ module Header
5
+ Status: 'Status'
6
+ Desc: 'Description'
7
+ MsgID: 'Nats-Msg-Id'
8
+ ExpectedStream: 'Nats-Expected-Stream'
9
+ ExpectedLastSeq: 'Nats-Expected-Last-Sequence'
10
+ ExpectedLastSubjSeq: 'Nats-Expected-Last-Subject-Sequence'
11
+ ExpectedLastMsgID: 'Nats-Expected-Last-Msg-Id'
12
+ LastConsumerSeq: 'Nats-Last-Consumer'
13
+ LastStreamSeq: 'Nats-Last-Stream'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ module Status
5
+ CtrlMsg: '100'
6
+ NoMsgs: '404'
7
+ NotFound: '404'
8
+ RequestTimeout: '408'
9
+ ServiceUnavailable: '503'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ module Sub
5
+ attr_reader js: NATS::JetStream
6
+ attr_reader stream: String
7
+ attr_reader consumer: String
8
+ attr_reader nms: String
9
+
10
+ def initialize: (Hash[Symbol, untyped]) -> void
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ module NATS
2
+ class JetStream
3
+ module JS
4
+ DefaultAPIPrefix: '$JS.API'
5
+
6
+ # class << self
7
+ def self.next_req_to_json: (Hash[Symbol, untyped]) -> String
8
+
9
+ def self.is_status_msg: (NATS::Msg) -> bool
10
+
11
+ def self.check_503_error: (NATS::Msg) -> void
12
+
13
+ def self.from_msg: (NATS::Msg) -> NATS::JetStream::API::Error
14
+
15
+ def self.from_error: (Hash[Symbol, untyped]) -> (
16
+ NATS::JetStream::Error::ServiceUnavailable |
17
+ NATS::JetStream::Error::ServerError |
18
+ NATS::JetStream::Error::StreamNotFound |
19
+ NATS::JetStream::Error::ConsumerNotFound |
20
+ NATS::JetStream::Error::NotFound |
21
+ NATS::JetStream::Error::BadRequest |
22
+ NATS::JetStream::API::Error
23
+ )
24
+ # end class << self
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module NATS
2
+ class JetStream
3
+ module Manager
4
+ def add_stream: (JetStream::API::StreamConfig, ?Hash[Symbol, untyped]) -> JetStream::API::StreamCreateResponse
5
+
6
+ def stream_info: (String, ?Hash[Symbol, untyped]) -> JetStream::API::StreamInfo
7
+
8
+ def update_stream: (JetStream::API::StreamConfig, ?Hash[Symbol, untyped]) -> JetStream::API::StreamCreateResponse
9
+
10
+ def delete_stream: (String, ?Hash[Symbol, untyped]) -> bool
11
+
12
+ def add_consumer: (String, JetStream::API::ConsumerConfig, ?Hash[Symbol, untyped]) -> JetStream::API::ConsumerInfo
13
+
14
+ def consumer_info: (String, String, ?Hash[Symbol, untyped]) -> JetStream::API::ConsumerInfo
15
+
16
+ def delete_consumer: (String, String, ?Hash[Symbol, untyped]) -> bool
17
+
18
+ def find_stream_name_by_subject: (String, ?Hash[Symbol, untyped]) -> String
19
+
20
+ def get_msg: (String, ?Hash[Symbol, untyped]) -> JetStream::API::RawStreamMsg
21
+
22
+ def get_last_msg: (String, String, ?Hash[Symbol, untyped]) -> JetStream::API::RawStreamMsg
23
+
24
+ def account_info: () -> Hash[Symbol, untyped]
25
+
26
+ private
27
+
28
+ def api_request: (String, String, ?Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
29
+
30
+ def _lift_msg_to_raw_msg: (NATS::Msg) -> JetStream::API::RawStreamMsg
31
+ end
32
+ end
33
+ end