nats-pure 0.7.2 → 2.4.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.
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,303 @@
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
+ module NATS
16
+ class JetStream
17
+ # A JetStream::Manager can be used to make requests to the JetStream API.
18
+ #
19
+ # @example
20
+ # require 'nats/client'
21
+ #
22
+ # nc = NATS.connect("demo.nats.io")
23
+ #
24
+ # config = JetStream::API::StreamConfig.new()
25
+ # nc.jsm.add_stream(config)
26
+ #
27
+ #
28
+ module Manager
29
+ # add_stream creates a stream with a given config.
30
+ # @param config [JetStream::API::StreamConfig] Configuration of the stream to create.
31
+ # @param params [Hash] Options to customize API request.
32
+ # @option params [Float] :timeout Time to wait for response.
33
+ # @return [JetStream::API::StreamCreateResponse] The result of creating a Stream.
34
+ def add_stream(config, params={})
35
+ config = if not config.is_a?(JetStream::API::StreamConfig)
36
+ JetStream::API::StreamConfig.new(config)
37
+ else
38
+ config
39
+ end
40
+ stream = config[:name]
41
+ raise ArgumentError.new(":name is required to create streams") unless stream
42
+ raise ArgumentError.new("Spaces, tabs, period (.), greater than (>) or asterisk (*) are prohibited in stream names") if stream =~ /(\s|\.|\>|\*)/
43
+ req_subject = "#{@prefix}.STREAM.CREATE.#{stream}"
44
+
45
+ cfg = config.to_h.compact
46
+ result = api_request(req_subject, cfg.to_json, params)
47
+ JetStream::API::StreamCreateResponse.new(result)
48
+ end
49
+
50
+ # stream_info retrieves the current status of a stream.
51
+ # @param stream [String] Name of the stream.
52
+ # @param params [Hash] Options to customize API request.
53
+ # @option params [Float] :timeout Time to wait for response.
54
+ # @return [JetStream::API::StreamInfo] The latest StreamInfo of the stream.
55
+ def stream_info(stream, params={})
56
+ raise JetStream::Error::InvalidStreamName.new("nats: invalid stream name") if stream.nil? or stream.empty?
57
+
58
+ req_subject = "#{@prefix}.STREAM.INFO.#{stream}"
59
+ result = api_request(req_subject, '', params)
60
+ JetStream::API::StreamInfo.new(result)
61
+ end
62
+
63
+ # update_stream edits an existed stream with a given config.
64
+ # @param config [JetStream::API::StreamConfig] Configuration of the stream to create.
65
+ # @param params [Hash] Options to customize API request.
66
+ # @option params [Float] :timeout Time to wait for response.
67
+ # @return [JetStream::API::StreamCreateResponse] The result of creating a Stream.
68
+ def update_stream(config, params={})
69
+ config = if not config.is_a?(JetStream::API::StreamConfig)
70
+ JetStream::API::StreamConfig.new(config)
71
+ else
72
+ config
73
+ end
74
+ stream = config[:name]
75
+ raise ArgumentError.new(":name is required to create streams") unless stream
76
+ raise ArgumentError.new("Spaces, tabs, period (.), greater than (>) or asterisk (*) are prohibited in stream names") if stream =~ /(\s|\.|\>|\*)/
77
+ req_subject = "#{@prefix}.STREAM.UPDATE.#{stream}"
78
+ cfg = config.to_h.compact
79
+ result = api_request(req_subject, cfg.to_json, params)
80
+ JetStream::API::StreamCreateResponse.new(result)
81
+ end
82
+
83
+ # delete_stream deletes a stream.
84
+ # @param stream [String] Name of the stream.
85
+ # @param params [Hash] Options to customize API request.
86
+ # @option params [Float] :timeout Time to wait for response.
87
+ # @return [Boolean]
88
+ def delete_stream(stream, params={})
89
+ raise JetStream::Error::InvalidStreamName.new("nats: invalid stream name") if stream.nil? or stream.empty?
90
+
91
+ req_subject = "#{@prefix}.STREAM.DELETE.#{stream}"
92
+ result = api_request(req_subject, '', params)
93
+ result[:success]
94
+ end
95
+
96
+ # add_consumer creates a consumer with a given config.
97
+ # @param stream [String] Name of the stream.
98
+ # @param config [JetStream::API::ConsumerConfig] Configuration of the consumer to create.
99
+ # @param params [Hash] Options to customize API request.
100
+ # @option params [Float] :timeout Time to wait for response.
101
+ # @return [JetStream::API::ConsumerInfo] The result of creating a Consumer.
102
+ def add_consumer(stream, config, params={})
103
+ raise JetStream::Error::InvalidStreamName.new("nats: invalid stream name") if stream.nil? or stream.empty?
104
+ config = if not config.is_a?(JetStream::API::ConsumerConfig)
105
+ JetStream::API::ConsumerConfig.new(config)
106
+ else
107
+ config
108
+ end
109
+ config[:name] ||= config[:durable_name]
110
+ req_subject = case
111
+ when config[:name]
112
+ ###############################################################################
113
+ # #
114
+ # Using names is the supported way of creating consumers (NATS +v2.9.0. #
115
+ # #
116
+ ###############################################################################
117
+ if config[:filter_subject] && config[:filter_subject] != ">"
118
+ "#{@prefix}.CONSUMER.CREATE.#{stream}.#{config[:name]}.#{config[:filter_subject]}"
119
+ else
120
+ ##############################################################################
121
+ # #
122
+ # Endpoint to support creating ANY consumer with multi-filters (NATS +v2.10) #
123
+ # #
124
+ ##############################################################################
125
+ "#{@prefix}.CONSUMER.CREATE.#{stream}.#{config[:name]}"
126
+ end
127
+ when config[:durable_name]
128
+ ###############################################################################
129
+ # #
130
+ # Endpoint to support creating DURABLES before NATS v2.9.0. #
131
+ # #
132
+ ###############################################################################
133
+ "#{@prefix}.CONSUMER.DURABLE.CREATE.#{stream}.#{config[:durable_name]}"
134
+ else
135
+ ###############################################################################
136
+ # #
137
+ # Endpoint to support creating EPHEMERALS before NATS v2.9.0. #
138
+ # #
139
+ ###############################################################################
140
+ "#{@prefix}.CONSUMER.CREATE.#{stream}"
141
+ end
142
+
143
+ config[:ack_policy] ||= JS::Config::AckExplicit
144
+ # Check if have to normalize ack wait so that it is in nanoseconds for Go compat.
145
+ if config[:ack_wait]
146
+ raise ArgumentError.new("nats: invalid ack wait") unless config[:ack_wait].is_a?(Integer)
147
+ config[:ack_wait] = config[:ack_wait] * ::NATS::NANOSECONDS
148
+ end
149
+ if config[:inactive_threshold]
150
+ raise ArgumentError.new("nats: invalid inactive threshold") unless config[:inactive_threshold].is_a?(Integer)
151
+ config[:inactive_threshold] = config[:inactive_threshold] * ::NATS::NANOSECONDS
152
+ end
153
+
154
+ cfg = config.to_h.compact
155
+ req = {
156
+ stream_name: stream,
157
+ config: cfg
158
+ }
159
+
160
+ result = api_request(req_subject, req.to_json, params)
161
+ JetStream::API::ConsumerInfo.new(result).freeze
162
+ end
163
+
164
+ # consumer_info retrieves the current status of a consumer.
165
+ # @param stream [String] Name of the stream.
166
+ # @param consumer [String] Name of the consumer.
167
+ # @param params [Hash] Options to customize API request.
168
+ # @option params [Float] :timeout Time to wait for response.
169
+ # @return [JetStream::API::ConsumerInfo] The latest ConsumerInfo of the consumer.
170
+ def consumer_info(stream, consumer, params={})
171
+ raise JetStream::Error::InvalidStreamName.new("nats: invalid stream name") if stream.nil? or stream.empty?
172
+ raise JetStream::Error::InvalidConsumerName.new("nats: invalid consumer name") if consumer.nil? or consumer.empty?
173
+
174
+ req_subject = "#{@prefix}.CONSUMER.INFO.#{stream}.#{consumer}"
175
+ result = api_request(req_subject, '', params)
176
+ JetStream::API::ConsumerInfo.new(result)
177
+ end
178
+
179
+ # delete_consumer deletes a consumer.
180
+ # @param stream [String] Name of the stream.
181
+ # @param consumer [String] Name of the consumer.
182
+ # @param params [Hash] Options to customize API request.
183
+ # @option params [Float] :timeout Time to wait for response.
184
+ # @return [Boolean]
185
+ def delete_consumer(stream, consumer, params={})
186
+ raise JetStream::Error::InvalidStreamName.new("nats: invalid stream name") if stream.nil? or stream.empty?
187
+ raise JetStream::Error::InvalidConsumerName.new("nats: invalid consumer name") if consumer.nil? or consumer.empty?
188
+
189
+ req_subject = "#{@prefix}.CONSUMER.DELETE.#{stream}.#{consumer}"
190
+ result = api_request(req_subject, '', params)
191
+ result[:success]
192
+ end
193
+
194
+ # find_stream_name_by_subject does a lookup for the stream to which
195
+ # the subject belongs.
196
+ # @param subject [String] The subject that belongs to a stream.
197
+ # @param params [Hash] Options to customize API request.
198
+ # @option params [Float] :timeout Time to wait for response.
199
+ # @return [String] The name of the JetStream stream for the subject.
200
+ def find_stream_name_by_subject(subject, params={})
201
+ req_subject = "#{@prefix}.STREAM.NAMES"
202
+ req = { subject: subject }
203
+ result = api_request(req_subject, req.to_json, params)
204
+ raise JetStream::Error::NotFound unless result[:streams]
205
+
206
+ result[:streams].first
207
+ end
208
+
209
+ # get_msg retrieves a message from the stream.
210
+ # @param stream_name [String] The stream_name.
211
+ # @param params [Hash] Options to customize API request.
212
+ # @option next [Boolean] Fetch the next message for a subject.
213
+ # @option seq [Integer] Sequence number of a message.
214
+ # @option subject [String] Subject of the message.
215
+ # @option direct [Boolean] Use direct mode to for faster access (requires NATS v2.9.0)
216
+ def get_msg(stream_name, params={})
217
+ req = {}
218
+ case
219
+ when params[:next]
220
+ req[:seq] = params[:seq]
221
+ req[:next_by_subj] = params[:subject]
222
+ when params[:seq]
223
+ req[:seq] = params[:seq]
224
+ when params[:subject]
225
+ req[:last_by_subj] = params[:subject]
226
+ end
227
+
228
+ data = req.to_json
229
+ if params[:direct]
230
+ if params[:subject] and not params[:seq]
231
+ # last_by_subject type request requires no payload.
232
+ data = ''
233
+ req_subject = "#{@prefix}.DIRECT.GET.#{stream_name}.#{params[:subject]}"
234
+ else
235
+ req_subject = "#{@prefix}.DIRECT.GET.#{stream_name}"
236
+ end
237
+ else
238
+ req_subject = "#{@prefix}.STREAM.MSG.GET.#{stream_name}"
239
+ end
240
+ resp = api_request(req_subject, data, direct: params[:direct])
241
+ msg = if params[:direct]
242
+ _lift_msg_to_raw_msg(resp)
243
+ else
244
+ JetStream::API::RawStreamMsg.new(resp[:message])
245
+ end
246
+
247
+ msg
248
+ end
249
+
250
+ def get_last_msg(stream_name, subject, params={})
251
+ params[:subject] = subject
252
+ get_msg(stream_name, params)
253
+ end
254
+
255
+ def account_info
256
+ api_request("#{@prefix}.INFO")
257
+ end
258
+
259
+ private
260
+
261
+ def api_request(req_subject, req="", params={})
262
+ params[:timeout] ||= @opts[:timeout]
263
+ msg = begin
264
+ @nc.request(req_subject, req, **params)
265
+ rescue NATS::IO::NoRespondersError
266
+ raise JetStream::Error::ServiceUnavailable
267
+ end
268
+
269
+ result = if params[:direct]
270
+ msg
271
+ else
272
+ JSON.parse(msg.data, symbolize_names: true)
273
+ end
274
+ if result.is_a?(Hash) and result[:error]
275
+ raise JS.from_error(result[:error])
276
+ end
277
+
278
+ result
279
+ end
280
+
281
+ def _lift_msg_to_raw_msg(msg)
282
+ if msg.header and msg.header['Status']
283
+ status = msg.header['Status']
284
+ if status == '404'
285
+ raise ::NATS::JetStream::Error::NotFound.new
286
+ else
287
+ raise JS.from_msg(msg)
288
+ end
289
+ end
290
+ subject = msg.header['Nats-Subject']
291
+ seq = msg.header['Nats-Sequence']
292
+ raw_msg = JetStream::API::RawStreamMsg.new(
293
+ subject: subject,
294
+ seq: seq,
295
+ headers: msg.header,
296
+ )
297
+ raw_msg.data = msg.data
298
+
299
+ raw_msg
300
+ end
301
+ end
302
+ end
303
+ end
@@ -0,0 +1,57 @@
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
+ module NATS
16
+ class JetStream
17
+ module Msg
18
+ module Ack
19
+ # Ack types
20
+ Ack = ("+ACK".freeze)
21
+ Nak = ("-NAK".freeze)
22
+ Progress = ("+WPI".freeze)
23
+ Term = ("+TERM".freeze)
24
+
25
+ Empty = (''.freeze)
26
+ DotSep = ('.'.freeze)
27
+ NoDomainName = ('_'.freeze)
28
+
29
+ # Position
30
+ Prefix0 = ('$JS'.freeze)
31
+ Prefix1 = ('ACK'.freeze)
32
+ Domain = 2
33
+ AccHash = 3
34
+ Stream = 4
35
+ Consumer = 5
36
+ NumDelivered = 6
37
+ StreamSeq = 7
38
+ ConsumerSeq = 8
39
+ Timestamp = 9
40
+ NumPending = 10
41
+
42
+ # Subject without domain:
43
+ # $JS.ACK.<stream>.<consumer>.<delivered>.<sseq>.<cseq>.<tm>.<pending>
44
+ #
45
+ V1TokenCounts = 9
46
+
47
+ # Subject with domain:
48
+ # $JS.ACK.<domain>.<account hash>.<stream>.<consumer>.<delivered>.<sseq>.<cseq>.<tm>.<pending>.<a token with a random value>
49
+ #
50
+ V2TokenCounts = 12
51
+
52
+ SequencePair = Struct.new(:stream, :consumer)
53
+ end
54
+ private_constant :Ack
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,111 @@
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
+ module NATS
16
+ class JetStream
17
+ module Msg
18
+ module AckMethods
19
+ def ack(**params)
20
+ ensure_is_acked_once!
21
+
22
+ resp = if params[:timeout]
23
+ @nc.request(@reply, Ack::Ack, **params)
24
+ else
25
+ @nc.publish(@reply, Ack::Ack)
26
+ end
27
+ @sub.synchronize { @ackd = true }
28
+
29
+ resp
30
+ end
31
+
32
+ def ack_sync(**params)
33
+ ensure_is_acked_once!
34
+
35
+ params[:timeout] ||= 0.5
36
+ resp = @nc.request(@reply, Ack::Ack, **params)
37
+ @sub.synchronize { @ackd = true }
38
+
39
+ resp
40
+ end
41
+
42
+ def nak(**params)
43
+ ensure_is_acked_once!
44
+ payload = if params[:delay]
45
+ payload = "#{Ack::Nak} #{{ delay: params[:delay] }.to_json}"
46
+ else
47
+ Ack::Nak
48
+ end
49
+ resp = if params[:timeout]
50
+ @nc.request(@reply, payload, **params)
51
+ else
52
+ @nc.publish(@reply, payload)
53
+ end
54
+ @sub.synchronize { @ackd = true }
55
+
56
+ resp
57
+ end
58
+
59
+ def term(**params)
60
+ ensure_is_acked_once!
61
+
62
+ resp = if params[:timeout]
63
+ @nc.request(@reply, Ack::Term, **params)
64
+ else
65
+ @nc.publish(@reply, Ack::Term)
66
+ end
67
+ @sub.synchronize { @ackd = true }
68
+
69
+ resp
70
+ end
71
+
72
+ def in_progress(**params)
73
+ params[:timeout] ? @nc.request(@reply, Ack::Progress, **params) : @nc.publish(@reply, Ack::Progress)
74
+ end
75
+
76
+ def metadata
77
+ @meta ||= parse_metadata(reply)
78
+ end
79
+
80
+ private
81
+
82
+ def ensure_is_acked_once!
83
+ @sub.synchronize do
84
+ if @ackd
85
+ raise JetStream::Error::MsgAlreadyAckd.new("nats: message was already acknowledged: #{self}")
86
+ end
87
+ end
88
+ end
89
+
90
+ def parse_metadata(reply)
91
+ tokens = reply.split(Ack::DotSep)
92
+ n = tokens.count
93
+
94
+ case
95
+ when n < Ack::V1TokenCounts || (n > Ack::V1TokenCounts and n < Ack::V2TokenCounts)
96
+ raise NotJSMessage.new("nats: not a jetstream message")
97
+ when tokens[0] != Ack::Prefix0 || tokens[1] != Ack::Prefix1
98
+ raise NotJSMessage.new("nats: not a jetstream message")
99
+ when n == Ack::V1TokenCounts
100
+ tokens.insert(Ack::Domain, Ack::Empty)
101
+ tokens.insert(Ack::AccHash, Ack::Empty)
102
+ when tokens[Ack::Domain] == Ack::NoDomainName
103
+ tokens[Ack::Domain] = Ack::Empty
104
+ end
105
+
106
+ Metadata.new(tokens)
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,37 @@
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 'time'
16
+
17
+ module NATS
18
+ class JetStream
19
+ module Msg
20
+ class Metadata
21
+ attr_reader :sequence, :num_delivered, :num_pending, :timestamp, :stream, :consumer, :domain
22
+
23
+ def initialize(opts)
24
+ @sequence = Ack::SequencePair.new(opts[Ack::StreamSeq].to_i, opts[Ack::ConsumerSeq].to_i)
25
+ @domain = opts[Ack::Domain]
26
+ @num_delivered = opts[Ack::NumDelivered].to_i
27
+ @num_pending = opts[Ack::NumPending].to_i
28
+ @timestamp = Time.at((opts[Ack::Timestamp].to_i / 1_000_000_000.0))
29
+ @stream = opts[Ack::Stream]
30
+ @consumer = opts[Ack::Consumer]
31
+ # TODO: Not exposed in Go client either right now.
32
+ # account = opts[Ack::AccHash]
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
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_relative 'msg/ack'
16
+ require_relative 'msg/ack_methods'
17
+ require_relative 'msg/metadata'
18
+
19
+ module NATS
20
+ class JetStream
21
+ # JetStream::Msg module includes the methods so that a regular NATS::Msg
22
+ # can be enhanced with JetStream features like acking and metadata.
23
+ module Msg
24
+ end
25
+ end
26
+ end