nats 0.8.4 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f530fc702ac09e68eab88e1c14f1765640f39231d1d359e330396eecbbb6540
4
- data.tar.gz: aeb4c366f71b70e16e636e13e0a0267239e9a654999dc7ab82a9c6f2d8ae720e
3
+ metadata.gz: 69469e7ad38954ab676e099443dc45f56bda0986a539cdcae552d7f760595eaa
4
+ data.tar.gz: ed8f954f8ae1da8bbca64a09dc57ae8ee532628ab9e8d871836ccc490f6d2266
5
5
  SHA512:
6
- metadata.gz: 7664e44a5c309ca972a694eccb35ef201b448ea970a19b1e202059adc611e104b95c3659f2a217743b76baf100e890921e15c5b6808b00bc6895d9a1a63c9392
7
- data.tar.gz: 54671440f1400fde1bb56ed99380e45853fa0ab71c0125f89c66846cd23e475c4d49869b5272e55a95b5b8685a4ed76e96248b8b59315cf6033c0f917e76c88d
6
+ metadata.gz: 1c924a60aa9d2380da3fb916cf7336f6c59d1c10c1685dc198577a5593aa84849c7c1839ce2d0ed818bed012aa2c7ca0fa27f16f665267ba49512dca44a2ff41
7
+ data.tar.gz: 10d496a25c6783ce15f92323dcbc76b927f2a7c6ea2fc196c46218f4d1cc6854a3ab303f560454977ee07d4fd5671431d94e164bfabb82b37d6dba5a89320413
data/HISTORY.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # HISTORY
2
2
 
3
+ ## v0.8.4 (Feb 23, 2018)
4
+ - Support to include connection `name` as part of CONNECT options (#145)
5
+ - Fixed support for Ruby 2.5 due to missing OpenSSL `require` (#144)
6
+
3
7
  ## v0.8.2 (March 14, 2017)
4
8
  - Allow setting name from client on connect (#129)
5
9
  - Add discovered servers helper for servers announced via async INFO (#136)
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  A [Ruby](http://ruby-lang.org) client for the [NATS messaging system](https://nats.io).
4
4
 
5
- [![License MIT](https://img.shields.io/npm/l/express.svg)](http://opensource.org/licenses/MIT)
6
- [![Build Status](https://travis-ci.org/nats-io/ruby-nats.svg)](http://travis-ci.org/nats-io/ruby-nats) [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&type=5&v=0.8.4)](https://rubygems.org/gems/nats/versions/0.8.4) [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/nats-io/ruby-nats)
5
+ [![License Apache 2.0](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
6
+ [![Build Status](https://travis-ci.org/nats-io/ruby-nats.svg)](http://travis-ci.org/nats-io/ruby-nats) [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&type=5&v=0.9.0)](https://rubygems.org/gems/nats/versions/0.9.0) [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/nats-io/ruby-nats)
7
7
 
8
8
  ## Supported Platforms
9
9
 
@@ -156,6 +156,8 @@ end
156
156
  NATS.connect { NATS.publish('test', 'Hello World!') }
157
157
  ```
158
158
 
159
+ See examples and benchmarks for more information..
160
+
159
161
  ### TLS
160
162
 
161
163
  Advanced customizations options for setting up a secure connection can
@@ -210,29 +212,78 @@ NATS.start(options) do |nats|
210
212
  end
211
213
  ```
212
214
 
213
- See examples and benchmarks for more information..
215
+ ### Fibers
214
216
 
215
- ## License
217
+ Requests without a callback can be made to work synchronously and return
218
+ the result when running in a Fiber. For these type of requests, it is
219
+ possible to set a timeout of how long to wait for a single or multiple
220
+ responses.
221
+
222
+ ```ruby
223
+ NATS.start {
216
224
 
217
- (The MIT License)
225
+ NATS.subscribe('help') do |msg, reply|
226
+ puts "[Received]: <<- #{msg}"
227
+ NATS.publish(reply, "I'll help! - #{msg}")
228
+ end
218
229
 
219
- Copyright (c) 2010-2018 Derek Collison
230
+ NATS.subscribe('slow') do |msg, reply|
231
+ puts "[Received]: <<- #{msg}"
232
+ EM.add_timer(1) { NATS.publish(reply, "I'll help! - #{msg}") }
233
+ end
220
234
 
221
- Permission is hereby granted, free of charge, to any person obtaining a copy
222
- of this software and associated documentation files (the "Software"), to
223
- deal in the Software without restriction, including without limitation the
224
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
225
- sell copies of the Software, and to permit persons to whom the Software is
226
- furnished to do so, subject to the following conditions:
235
+ 10.times do |n|
236
+ NATS.subscribe('hi') do |msg, reply|
237
+ NATS.publish(reply, "Hello World! - id:#{n}")
238
+ end
239
+ end
227
240
 
228
- The above copyright notice and this permission notice shall be included in
229
- all copies or substantial portions of the Software.
241
+ Fiber.new do
242
+ # Requests work synchronously within the same Fiber
243
+ # returning the message when done.
244
+ response = NATS.request('help', 'foo')
245
+ puts "[Response]: ->> '#{response}'"
246
+
247
+ # Specifying a custom timeout to give up waiting for
248
+ # a response.
249
+ response = NATS.request('slow', 'bar', timeout: 2)
250
+ if response.nil?
251
+ puts "No response after 2 seconds..."
252
+ else
253
+ puts "[Response]: ->> '#{response}'"
254
+ end
255
+
256
+ # Can gather multiple responses with the same request
257
+ # which will then return a collection with the responses
258
+ # that were received before the timeout.
259
+ responses = NATS.request('hi', 'quux', max: 10, timeout: 1)
260
+ responses.each_with_index do |response, i|
261
+ puts "[Response# #{i}]: ->> '#{response}'"
262
+ end
263
+
264
+ # If no replies then an empty collection is returned.
265
+ responses = NATS.request('nowhere', '', max: 10, timeout: 2)
266
+ if responses.any?
267
+ puts "Got #{responses.count} responses"
268
+ else
269
+ puts "No response after 2 seconds..."
270
+ end
271
+
272
+ NATS.stop
273
+ end.resume
274
+
275
+ # Multiple fibers can make requests concurrently
276
+ # under the same Eventmachine loop.
277
+ Fiber.new do
278
+ 10.times do |n|
279
+ response = NATS.request('help', "help.#{n}")
280
+ puts "[Response]: ->> '#{response}'"
281
+ end
282
+ end.resume
283
+ }
284
+ ```
230
285
 
231
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
232
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
233
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
234
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
235
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
236
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
237
- IN THE SOFTWARE.
286
+ ## License
238
287
 
288
+ Unless otherwise noted, the NATS source files are distributed under
289
+ the Apache Version 2.0 license found in the LICENSE file.
data/Rakefile CHANGED
@@ -1,4 +1,18 @@
1
1
  #!/usr/bin/env rake
2
+ # Copyright 2010-2018 The NATS Authors
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+
2
16
  require 'rspec/core'
3
17
  require 'rspec/core/rake_task'
4
18
 
@@ -1,4 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+ # Copyright 2010-2018 The NATS Authors
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
2
15
 
3
16
  require 'optparse'
4
17
  require 'rubygems'
@@ -1,4 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+ # Copyright 2010-2018 The NATS Authors
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
2
15
 
3
16
  require 'optparse'
4
17
  require 'rubygems'
@@ -1,4 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+ # Copyright 2010-2018 The NATS Authors
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
2
15
 
3
16
  require 'optparse'
4
17
  require 'rubygems'
@@ -1,4 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
+ # Copyright 2010-2018 The NATS Authors
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+
2
16
  # NATS command line interface script.
3
17
  # Run <tt>nats-server -h</tt> to get more usage.
4
18
 
@@ -1,4 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+ # Copyright 2010-2018 The NATS Authors
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
2
15
 
3
16
  require 'optparse'
4
17
  require 'rubygems'
@@ -1,4 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+ # Copyright 2010-2018 The NATS Authors
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
2
15
 
3
16
  require 'optparse'
4
17
  require 'net/http'
@@ -1,5 +1,20 @@
1
+ # Copyright 2010-2018 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
+
1
15
  require 'uri'
2
16
  require 'securerandom'
17
+ require 'fiber'
3
18
  require 'openssl' unless defined?(OpenSSL)
4
19
 
5
20
  ep = File.expand_path(File.dirname(__FILE__))
@@ -8,6 +23,7 @@ require "#{ep}/ext/em"
8
23
  require "#{ep}/ext/bytesize"
9
24
  require "#{ep}/ext/json"
10
25
  require "#{ep}/version"
26
+ require "#{ep}/nuid"
11
27
 
12
28
  module NATS
13
29
 
@@ -361,6 +377,12 @@ module NATS
361
377
  @tls = options[:tls] if options[:tls]
362
378
  @ssl = options[:ssl] if options[:ssl] or @tls
363
379
 
380
+ # New style request/response implementation.
381
+ @resp_sub = nil
382
+ @resp_map = nil
383
+ @resp_sub_prefix = nil
384
+ @nuid = NATS::NUID.new
385
+
364
386
  send_connect_command
365
387
  end
366
388
 
@@ -446,16 +468,108 @@ module NATS
446
468
  # @return [Object] sid
447
469
  def request(subject, data=nil, opts={}, &cb)
448
470
  return unless subject
449
- inbox = NATS.create_inbox
450
- s = subscribe(inbox, opts) { |msg, reply|
451
- case cb.arity
471
+
472
+ # In case of using async request then fallback to auto unsubscribe
473
+ # based request/response and not break compatibility too much since
474
+ # new request/response style can only be used with fibers.
475
+ if cb
476
+ inbox = "_INBOX.#{@nuid.next}"
477
+ s = subscribe(inbox, opts) { |msg, reply|
478
+ case cb.arity
452
479
  when 0 then cb.call
453
480
  when 1 then cb.call(msg)
454
481
  else cb.call(msg, reply)
455
- end
456
- }
482
+ end
483
+ }
484
+ publish(subject, data, inbox)
485
+ return s
486
+ end
487
+
488
+ # If this is the first request being made, then need to start
489
+ # the responses mux handler that handles the responses.
490
+ start_resp_mux_sub! unless @resp_sub_prefix
491
+
492
+ # Generate unique token for the reply subject.
493
+ token = @nuid.next
494
+ inbox = "#{@resp_sub_prefix}.#{token}"
495
+
496
+ # Synchronous request/response requires using a Fiber
497
+ # to be able to await the response.
498
+ f = Fiber.current
499
+ @resp_map[token][:fiber] = f
500
+
501
+ # If awaiting more than a single response then use array
502
+ # to include all that could be gathered before the deadline.
503
+ expected = opts[:max] ||= 1
504
+ @resp_map[token][:expected] = expected
505
+ @resp_map[token][:msgs] = [] if expected > 1
506
+
507
+ # Announce the request with the inbox using the token.
457
508
  publish(subject, data, inbox)
458
- return s
509
+
510
+ # If deadline expires, then discard the token and resume fiber
511
+ opts[:timeout] ||= 0.5
512
+ t = EM.add_timer(opts[:timeout]) do
513
+ if expected > 1
514
+ f.resume @resp_map[token][:msgs]
515
+ else
516
+ f.resume
517
+ end
518
+
519
+ @resp_map.delete(token)
520
+ end
521
+
522
+ # Wait for the response and cancel timeout callback if received.
523
+ if expected > 1
524
+ # Wait to receive all replies that can get before deadline.
525
+ msgs = Fiber.yield
526
+ EM.cancel_timer(t)
527
+
528
+ # Slice and throwaway responses that are not needed.
529
+ return msgs.slice(0, expected)
530
+ else
531
+ msg = Fiber.yield
532
+ EM.cancel_timer(t)
533
+ return msg
534
+ end
535
+ end
536
+
537
+ def start_resp_mux_sub!
538
+ @resp_sub_prefix = "_INBOX.#{@nuid.next}"
539
+ @resp_map = Hash.new { |h,k| h[k] = { }}
540
+
541
+ # Single subscription that will be handling all the requests
542
+ # using fibers to yield the responses.
543
+ subscribe("#{@resp_sub_prefix}.*") do |msg, reply, subject|
544
+ token = subject.split('.').last
545
+
546
+ # Discard the response if requestor not interested already.
547
+ next unless @resp_map.key? token
548
+
549
+ # Take fiber that will be passed the response
550
+ f = @resp_map[token][:fiber]
551
+ expected = @resp_map[token][:expected]
552
+
553
+ if expected == 1
554
+ f.resume msg
555
+ @resp_map.delete(token)
556
+ next
557
+ end
558
+
559
+ if @resp_map[token][:msgs].size < expected
560
+ @resp_map[token][:msgs] << msg
561
+
562
+ msgs = @resp_map[token][:msgs]
563
+ if msgs.size >= expected
564
+ f.resume(msgs)
565
+ else
566
+ # Wait to gather more messages or timeout.
567
+ next
568
+ end
569
+ end
570
+
571
+ @resp_map.delete(token)
572
+ end
459
573
  end
460
574
 
461
575
  # Flushes all messages and subscriptions for the connection.
@@ -1,3 +1,17 @@
1
+ # Copyright 2010-2018 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
+
1
15
  if RUBY_VERSION <= "1.8.6"
2
16
  class String #:nodoc:
3
17
  def bytesize; self.size; end
@@ -1,3 +1,17 @@
1
+ # Copyright 2010-2018 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
+
1
15
  begin
2
16
  require 'eventmachine'
3
17
  rescue LoadError
@@ -1,3 +1,17 @@
1
+ # Copyright 2010-2018 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
+
1
15
  begin
2
16
  require 'yajl'
3
17
  require 'yajl/json_gem'
@@ -0,0 +1,72 @@
1
+ # Copyright 2016-2018 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
+ require 'securerandom'
15
+
16
+ module NATS
17
+ class NUID
18
+ DIGITS = [*'0'..'9', *'A'..'Z', *'a'..'z']
19
+ BASE = 62
20
+ PREFIX_LENGTH = 12
21
+ SEQ_LENGTH = 10
22
+ TOTAL_LENGTH = PREFIX_LENGTH + SEQ_LENGTH
23
+ MAX_SEQ = BASE**10
24
+ MIN_INC = 33
25
+ MAX_INC = 333
26
+ INC = MAX_INC - MIN_INC
27
+
28
+ def initialize
29
+ @prand = Random.new
30
+ @seq = @prand.rand(MAX_SEQ)
31
+ @inc = MIN_INC + @prand.rand(INC)
32
+ @prefix = ''
33
+ randomize_prefix!
34
+ end
35
+
36
+ def next
37
+ @seq += @inc
38
+ if @seq >= MAX_SEQ
39
+ randomize_prefix!
40
+ reset_sequential!
41
+ end
42
+ l = @seq
43
+
44
+ # Do this inline 10 times to avoid even more extra allocs,
45
+ # then use string interpolation of everything which works
46
+ # faster for doing concat.
47
+ s_10 = DIGITS[l % BASE];
48
+
49
+ # Ugly, but parallel assignment is slightly faster here...
50
+ s_09, s_08, s_07, s_06, s_05, s_04, s_03, s_02, s_01 = \
51
+ (l /= BASE; DIGITS[l % BASE]), (l /= BASE; DIGITS[l % BASE]), (l /= BASE; DIGITS[l % BASE]),\
52
+ (l /= BASE; DIGITS[l % BASE]), (l /= BASE; DIGITS[l % BASE]), (l /= BASE; DIGITS[l % BASE]),\
53
+ (l /= BASE; DIGITS[l % BASE]), (l /= BASE; DIGITS[l % BASE]), (l /= BASE; DIGITS[l % BASE])
54
+ "#{@prefix}#{s_01}#{s_02}#{s_03}#{s_04}#{s_05}#{s_06}#{s_07}#{s_08}#{s_09}#{s_10}"
55
+ end
56
+
57
+ def randomize_prefix!
58
+ @prefix = \
59
+ SecureRandom.random_bytes(PREFIX_LENGTH).each_byte
60
+ .reduce('') do |prefix, n|
61
+ prefix << DIGITS[n % BASE]
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def reset_sequential!
68
+ @seq = @prand.rand(MAX_SEQ)
69
+ @inc = MIN_INC + @prand.rand(INC)
70
+ end
71
+ end
72
+ end
@@ -1,3 +1,16 @@
1
+ # Copyright 2010-2018 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
+ #
1
14
 
2
15
  require 'socket'
3
16
  require 'fileutils'
@@ -1,6 +1,20 @@
1
+ # Copyright 2010-2018 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
+
1
15
  module NATS
2
16
  # NOTE: These are all announced to the server on CONNECT
3
- VERSION = "0.8.4".freeze
17
+ VERSION = "0.9.0".freeze
4
18
  LANG = RUBY_ENGINE
5
19
  PROTOCOL_VERSION = 1
6
20
  end
@@ -1,4 +1,16 @@
1
-
1
+ # Copyright 2010-2018 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
+ #
2
14
 
3
15
  lib = File.expand_path('../lib/', __FILE__)
4
16
  $:.unshift lib unless $:.include?(lib)
@@ -12,7 +24,6 @@ spec = Gem::Specification.new do |s|
12
24
  s.homepage = 'https://nats.io'
13
25
  s.description = 'NATS is an open-source, high-performance, lightweight cloud messaging system.'
14
26
  s.licenses = ['MIT']
15
- s.has_rdoc = true
16
27
 
17
28
  s.authors = ['Derek Collison']
18
29
  s.email = ['derek.collison@gmail.com']
@@ -23,7 +34,6 @@ spec = Gem::Specification.new do |s|
23
34
  s.executables = ['nats-pub', 'nats-sub', 'nats-queue', 'nats-request']
24
35
 
25
36
  s.files = %w[
26
- COPYING
27
37
  README.md
28
38
  HISTORY.md
29
39
  nats.gemspec
@@ -35,6 +45,7 @@ spec = Gem::Specification.new do |s|
35
45
  bin/nats-top
36
46
  bin/nats-request
37
47
  lib/nats/client.rb
48
+ lib/nats/nuid.rb
38
49
  lib/nats/version.rb
39
50
  lib/nats/ext/bytesize.rb
40
51
  lib/nats/ext/em.rb
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Collison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-23 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -42,7 +42,6 @@ executables:
42
42
  extensions: []
43
43
  extra_rdoc_files: []
44
44
  files:
45
- - COPYING
46
45
  - HISTORY.md
47
46
  - README.md
48
47
  - Rakefile
@@ -56,6 +55,7 @@ files:
56
55
  - lib/nats/ext/bytesize.rb
57
56
  - lib/nats/ext/em.rb
58
57
  - lib/nats/ext/json.rb
58
+ - lib/nats/nuid.rb
59
59
  - lib/nats/server.rb
60
60
  - lib/nats/server/cluster.rb
61
61
  - lib/nats/server/connection.rb
data/COPYING DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2010, 2011 Derek Collison <derek.collison@gmail.com>. All rights reserved.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to
5
- deal in the Software without restriction, including without limitation the
6
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
- sell copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
- IN THE SOFTWARE.