nats-pure 2.2.0 → 2.2.1

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.
@@ -0,0 +1,60 @@
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 '../errors'
16
+
17
+ module NATS
18
+ class KeyValue
19
+ class Error < NATS::Error; end
20
+
21
+ # When a key is not found.
22
+ class KeyNotFoundError < Error
23
+ attr_reader :entry, :op
24
+ def initialize(params={})
25
+ @entry = params[:entry]
26
+ @op = params[:op]
27
+ @message = params[:message]
28
+ end
29
+
30
+ def to_s
31
+ msg = "nats: key not found"
32
+ msg = "#{msg}: #{@message}" if @message
33
+ msg
34
+ end
35
+ end
36
+
37
+ # When a key is not found because it was deleted.
38
+ class KeyDeletedError < KeyNotFoundError
39
+ def to_s
40
+ "nats: key was deleted"
41
+ end
42
+ end
43
+
44
+ # When there was no bucket present.
45
+ class BucketNotFoundError < Error; end
46
+
47
+ # When it is an invalid bucket.
48
+ class BadBucketError < Error; end
49
+
50
+ # When the result is an unexpected sequence.
51
+ class KeyWrongLastSequenceError < Error
52
+ def initialize(msg)
53
+ @msg = msg
54
+ end
55
+ def to_s
56
+ "nats: #{@msg}"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,89 @@
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 KeyValue
17
+ module Manager
18
+ def key_value(bucket)
19
+ stream = "KV_#{bucket}"
20
+ begin
21
+ si = stream_info(stream)
22
+ rescue NATS::JetStream::Error::NotFound
23
+ raise BucketNotFoundError.new("nats: bucket not found")
24
+ end
25
+ if si.config.max_msgs_per_subject < 1
26
+ raise BadBucketError.new("nats: bad bucket")
27
+ end
28
+
29
+ KeyValue.new(
30
+ name: bucket,
31
+ stream: stream,
32
+ pre: "$KV.#{bucket}.",
33
+ js: self,
34
+ direct: si.config.allow_direct
35
+ )
36
+ end
37
+
38
+ def create_key_value(config)
39
+ config = if not config.is_a?(KeyValue::API::KeyValueConfig)
40
+ KeyValue::API::KeyValueConfig.new(config)
41
+ else
42
+ config
43
+ end
44
+ config.history ||= 1
45
+ config.replicas ||= 1
46
+ duplicate_window = 2 * 60 # 2 minutes
47
+ if config.ttl
48
+ if config.ttl < duplicate_window
49
+ duplicate_window = config.ttl
50
+ end
51
+ config.ttl = config.ttl * ::NATS::NANOSECONDS
52
+ end
53
+
54
+ stream = JetStream::API::StreamConfig.new(
55
+ name: "KV_#{config.bucket}",
56
+ description: config.description,
57
+ subjects: ["$KV.#{config.bucket}.>"],
58
+ allow_direct: config.direct,
59
+ allow_rollup_hdrs: true,
60
+ deny_delete: true,
61
+ discard: "new",
62
+ duplicate_window: duplicate_window * ::NATS::NANOSECONDS,
63
+ max_age: config.ttl,
64
+ max_bytes: config.max_bytes,
65
+ max_consumers: -1,
66
+ max_msg_size: config.max_value_size,
67
+ max_msgs: -1,
68
+ max_msgs_per_subject: config.history,
69
+ num_replicas: config.replicas,
70
+ storage: config.storage,
71
+ republish: config.republish,
72
+ )
73
+
74
+ si = add_stream(stream)
75
+ KeyValue.new(
76
+ name: config.bucket,
77
+ stream: stream.name,
78
+ pre: "$KV.#{config.bucket}.",
79
+ js: self,
80
+ direct: si.config.allow_direct
81
+ )
82
+ end
83
+
84
+ def delete_key_value(bucket)
85
+ delete_stream("KV_#{bucket}")
86
+ end
87
+ end
88
+ end
89
+ end
data/lib/nats/io/kv.rb CHANGED
@@ -11,7 +11,11 @@
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
13
  #
14
- require_relative 'errors'
14
+
15
+ require_relative 'kv/api'
16
+ require_relative 'kv/bucket_status'
17
+ require_relative 'kv/errors'
18
+ require_relative 'kv/manager'
15
19
 
16
20
  module NATS
17
21
  class KeyValue
@@ -30,47 +34,6 @@ module NATS
30
34
  @direct = opts[:direct]
31
35
  end
32
36
 
33
- class Error < NATS::Error; end
34
-
35
- # When a key is not found.
36
- class KeyNotFoundError < Error
37
- attr_reader :entry, :op
38
- def initialize(params={})
39
- @entry = params[:entry]
40
- @op = params[:op]
41
- @message = params[:message]
42
- end
43
-
44
- def to_s
45
- msg = "nats: key not found"
46
- msg = "#{msg}: #{@message}" if @message
47
- msg
48
- end
49
- end
50
-
51
- # When a key is not found because it was deleted.
52
- class KeyDeletedError < KeyNotFoundError
53
- def to_s
54
- "nats: key was deleted"
55
- end
56
- end
57
-
58
- # When there was no bucket present.
59
- class BucketNotFoundError < Error; end
60
-
61
- # When it is an invalid bucket.
62
- class BadBucketError < Error; end
63
-
64
- # When the result is an unexpected sequence.
65
- class KeyWrongLastSequenceError < Error
66
- def initialize(msg)
67
- @msg = msg
68
- end
69
- def to_s
70
- "nats: #{@msg}"
71
- end
72
- end
73
-
74
37
  # get returns the latest value for the key.
75
38
  def get(key, params={})
76
39
  entry = nil
@@ -211,120 +174,5 @@ module NATS
211
174
  super(opts)
212
175
  end
213
176
  end
214
-
215
- class BucketStatus
216
- attr_reader :bucket
217
-
218
- def initialize(info, bucket)
219
- @nfo = info
220
- @bucket = bucket
221
- end
222
-
223
- def values
224
- @nfo.state.messages
225
- end
226
-
227
- def history
228
- @nfo.config.max_msgs_per_subject
229
- end
230
-
231
- def ttl
232
- @nfo.config.max_age / ::NATS::NANOSECONDS
233
- end
234
- end
235
-
236
- module API
237
- KeyValueConfig = Struct.new(
238
- :bucket,
239
- :description,
240
- :max_value_size,
241
- :history,
242
- :ttl,
243
- :max_bytes,
244
- :storage,
245
- :replicas,
246
- :placement,
247
- :republish,
248
- :direct,
249
- keyword_init: true) do
250
- def initialize(opts={})
251
- rem = opts.keys - members
252
- opts.delete_if { |k| rem.include?(k) }
253
- super(opts)
254
- end
255
- end
256
- end
257
-
258
- module Manager
259
- def key_value(bucket)
260
- stream = "KV_#{bucket}"
261
- begin
262
- si = stream_info(stream)
263
- rescue NATS::JetStream::Error::NotFound
264
- raise BucketNotFoundError.new("nats: bucket not found")
265
- end
266
- if si.config.max_msgs_per_subject < 1
267
- raise BadBucketError.new("nats: bad bucket")
268
- end
269
-
270
- KeyValue.new(
271
- name: bucket,
272
- stream: stream,
273
- pre: "$KV.#{bucket}.",
274
- js: self,
275
- direct: si.config.allow_direct
276
- )
277
- end
278
-
279
- def create_key_value(config)
280
- config = if not config.is_a?(KeyValue::API::KeyValueConfig)
281
- KeyValue::API::KeyValueConfig.new(config)
282
- else
283
- config
284
- end
285
- config.history ||= 1
286
- config.replicas ||= 1
287
- duplicate_window = 2 * 60 # 2 minutes
288
- if config.ttl
289
- if config.ttl < duplicate_window
290
- duplicate_window = config.ttl
291
- end
292
- config.ttl = config.ttl * ::NATS::NANOSECONDS
293
- end
294
-
295
- stream = JetStream::API::StreamConfig.new(
296
- name: "KV_#{config.bucket}",
297
- description: config.description,
298
- subjects: ["$KV.#{config.bucket}.>"],
299
- allow_direct: config.direct,
300
- allow_rollup_hdrs: true,
301
- deny_delete: true,
302
- discard: "new",
303
- duplicate_window: duplicate_window * ::NATS::NANOSECONDS,
304
- max_age: config.ttl,
305
- max_bytes: config.max_bytes,
306
- max_consumers: -1,
307
- max_msg_size: config.max_value_size,
308
- max_msgs: -1,
309
- max_msgs_per_subject: config.history,
310
- num_replicas: config.replicas,
311
- storage: config.storage,
312
- republish: config.republish,
313
- )
314
-
315
- si = add_stream(stream)
316
- KeyValue.new(
317
- name: config.bucket,
318
- stream: stream.name,
319
- pre: "$KV.#{config.bucket}.",
320
- js: self,
321
- direct: si.config.allow_direct
322
- )
323
- end
324
-
325
- def delete_key_value(bucket)
326
- delete_stream("KV_#{bucket}")
327
- end
328
- end
329
177
  end
330
178
  end
data/lib/nats/io/msg.rb CHANGED
@@ -11,7 +11,7 @@
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
13
  #
14
- require_relative 'js'
14
+ require_relative 'jetstream'
15
15
 
16
16
  module NATS
17
17
  class Msg
@@ -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.2.0".freeze
18
+ VERSION = "2.2.1".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
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.2.0
4
+ version: 2.2.1
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-10-01 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: NATS is an open-source, high-performance, lightweight cloud messaging
14
14
  system.
@@ -22,8 +22,26 @@ files:
22
22
  - lib/nats/client.rb
23
23
  - lib/nats/io/client.rb
24
24
  - lib/nats/io/errors.rb
25
- - lib/nats/io/js.rb
25
+ - lib/nats/io/jetstream.rb
26
+ - lib/nats/io/jetstream/api.rb
27
+ - lib/nats/io/jetstream/errors.rb
28
+ - lib/nats/io/jetstream/js.rb
29
+ - lib/nats/io/jetstream/js/config.rb
30
+ - lib/nats/io/jetstream/js/header.rb
31
+ - lib/nats/io/jetstream/js/status.rb
32
+ - lib/nats/io/jetstream/js/sub.rb
33
+ - lib/nats/io/jetstream/manager.rb
34
+ - lib/nats/io/jetstream/msg.rb
35
+ - lib/nats/io/jetstream/msg/ack.rb
36
+ - lib/nats/io/jetstream/msg/ack_methods.rb
37
+ - lib/nats/io/jetstream/msg/metadata.rb
38
+ - lib/nats/io/jetstream/pull_subscription.rb
39
+ - lib/nats/io/jetstream/push_subscription.rb
26
40
  - lib/nats/io/kv.rb
41
+ - lib/nats/io/kv/api.rb
42
+ - lib/nats/io/kv/bucket_status.rb
43
+ - lib/nats/io/kv/errors.rb
44
+ - lib/nats/io/kv/manager.rb
27
45
  - lib/nats/io/msg.rb
28
46
  - lib/nats/io/parser.rb
29
47
  - lib/nats/io/subscription.rb