nats 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +11 -0
- data/README.md +25 -4
- data/bin/nats-pub +1 -1
- data/bin/nats-queue +1 -1
- data/bin/nats-request +1 -1
- data/bin/nats-sub +1 -1
- data/lib/nats/client.rb +43 -7
- data/lib/nats/version.rb +4 -1
- data/nats.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23d54c2e2890b69cdb422808a4f94a93a6cac269
|
4
|
+
data.tar.gz: 55c83a91c62c749121200bf33fd82d0d1fd021ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5bf18160bb411b9cff709e4d0c9bc236cbdeb2c84e28f2745e0be7bd806f010df525ffd13d7971ce6b51e51a451c066c39b6c3dfacfe2a66c2da6917e537946
|
7
|
+
data.tar.gz: 7257c4a1d832e49c2bcc0df2a3b4e5ad162e44d1a8062b9510dd84c8a5748c8dde7c44c9eda398fb421a7d1d62ac721488fcb17ed830d9b91fd17f192b1823eb
|
data/HISTORY.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# HISTORY
|
2
2
|
|
3
|
+
## v0.8.2 (March 14, 2017)
|
4
|
+
- Allow setting name from client on connect (#129)
|
5
|
+
- Add discovered servers helper for servers announced via async INFO (#136)
|
6
|
+
- Add time based reconnect backoff (#139)
|
7
|
+
- Modify lang sent on connect when using jruby (#135)
|
8
|
+
|
9
|
+
## v0.8.0 (August 10, 2016)
|
10
|
+
- Added cluster auto discovery handling which is supported on v0.9.2 server release (#125)
|
11
|
+
- Added jruby part of the build (both in openjdk and oraclejdk runtimes) (#122 #123)
|
12
|
+
- Fixed ping interval accounting (#120)
|
13
|
+
|
3
14
|
## v0.7.1 (July 8, 2016)
|
4
15
|
- Remove dependencies which are no longer needed for ruby-client
|
5
16
|
- See full list @ https://github.com/nats-io/ruby-nats/compare/v0.7.0...v0.7.1
|
data/README.md
CHANGED
@@ -3,15 +3,14 @@
|
|
3
3
|
A [Ruby](http://ruby-lang.org) client for the [NATS messaging system](https://nats.io).
|
4
4
|
|
5
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.
|
7
|
-
|
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.0)](https://rubygems.org/gems/nats/versions/0.8.0) [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/nats-io/ruby-nats)
|
8
7
|
|
9
8
|
## Supported Platforms
|
10
9
|
|
11
10
|
This gem and the client are known to work on the following Ruby platforms:
|
12
11
|
|
13
12
|
- MRI 1.9, 2.0, 2.1, 2.2, 2.3.0
|
14
|
-
- JRuby 1.
|
13
|
+
- JRuby 9.1.2.0
|
15
14
|
|
16
15
|
## Getting Started
|
17
16
|
|
@@ -96,14 +95,36 @@ end
|
|
96
95
|
opts = {
|
97
96
|
:dont_randomize_servers => true,
|
98
97
|
:reconnect_time_wait => 0.5,
|
99
|
-
:max_reconnect_attempts
|
98
|
+
:max_reconnect_attempts => 10,
|
100
99
|
:servers => ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223', 'nats://127.0.0.1:4224']
|
101
100
|
}
|
102
101
|
|
103
102
|
NATS.connect(opts) do |c|
|
104
103
|
puts "NATS is connected!"
|
105
104
|
end
|
105
|
+
```
|
106
|
+
|
107
|
+
### Auto discovery
|
108
|
+
|
109
|
+
Starting from release `0.8.0` of the gem, the client also auto discovers
|
110
|
+
new nodes announced by the server as they attach to the cluster.
|
111
|
+
Reconnection logic parameters such as time to back-off on failure and max attempts
|
112
|
+
apply the same to both discovered nodes and those defined explicitly on connect:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
opts = {
|
116
|
+
:dont_randomize_servers => true,
|
117
|
+
:reconnect_time_wait => 0.5,
|
118
|
+
:max_reconnect_attempts => 10,
|
119
|
+
:servers => ['nats://127.0.0.1:4222', 'nats://127.0.0.1:4223'],
|
120
|
+
:user => 'secret',
|
121
|
+
:pass => 'deadbeef'
|
122
|
+
}
|
106
123
|
|
124
|
+
NATS.connect(opts) do |c|
|
125
|
+
# Confirm number of available servers in cluster.
|
126
|
+
puts "Connected to NATS! Servers in pool: #{c.server_pool.count}"
|
127
|
+
end
|
107
128
|
```
|
108
129
|
|
109
130
|
## Advanced Usage
|
data/bin/nats-pub
CHANGED
data/bin/nats-queue
CHANGED
@@ -41,7 +41,7 @@ end
|
|
41
41
|
|
42
42
|
NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
|
43
43
|
|
44
|
-
NATS.start(:uri => $nats_server
|
44
|
+
NATS.start(:uri => $nats_server) do
|
45
45
|
puts "Listening on [#{subject}], queue group [#{queue_group}]" unless $show_raw
|
46
46
|
NATS.subscribe(subject, :queue => queue_group) { |msg, _, sub|
|
47
47
|
puts decorate(sub, msg)
|
data/bin/nats-request
CHANGED
@@ -42,7 +42,7 @@ end
|
|
42
42
|
|
43
43
|
NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
|
44
44
|
|
45
|
-
NATS.start(:uri => $nats_server
|
45
|
+
NATS.start(:uri => $nats_server) do
|
46
46
|
NATS.request(subject, msg) { |(msg, reply)|
|
47
47
|
puts decorate(msg)
|
48
48
|
exit! if $responses && ($responses-=1) < 1
|
data/bin/nats-sub
CHANGED
@@ -40,7 +40,7 @@ end
|
|
40
40
|
|
41
41
|
NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
|
42
42
|
|
43
|
-
NATS.start(:uri => $nats_server
|
43
|
+
NATS.start(:uri => $nats_server) do
|
44
44
|
puts "Listening on [#{subject}]" unless $show_raw
|
45
45
|
NATS.subscribe(subject) { |msg, _, sub| puts decorate(sub, msg) }
|
46
46
|
end
|
data/lib/nats/client.rb
CHANGED
@@ -10,7 +10,6 @@ require "#{ep}/version"
|
|
10
10
|
|
11
11
|
module NATS
|
12
12
|
|
13
|
-
PROTOCOL_VERSION = 1
|
14
13
|
DEFAULT_PORT = 4222
|
15
14
|
DEFAULT_URI = "nats://localhost:#{DEFAULT_PORT}".freeze
|
16
15
|
|
@@ -519,14 +518,15 @@ module NATS
|
|
519
518
|
cs = {
|
520
519
|
:verbose => @options[:verbose],
|
521
520
|
:pedantic => @options[:pedantic],
|
522
|
-
:lang =>
|
523
|
-
:version => VERSION,
|
524
|
-
:protocol => PROTOCOL_VERSION
|
521
|
+
:lang => ::NATS::LANG,
|
522
|
+
:version => ::NATS::VERSION,
|
523
|
+
:protocol => ::NATS::PROTOCOL_VERSION
|
525
524
|
}
|
526
525
|
if auth_connection?
|
527
526
|
cs[:user] = @uri.user
|
528
527
|
cs[:pass] = @uri.password
|
529
528
|
end
|
529
|
+
cs[:name] = @options[:name] if @options[:name]
|
530
530
|
cs[:ssl_required] = @ssl if @ssl
|
531
531
|
cs[:tls_required] = true if @tls
|
532
532
|
|
@@ -680,7 +680,7 @@ module NATS
|
|
680
680
|
u.password ||= @uri.password if @uri.password
|
681
681
|
end
|
682
682
|
|
683
|
-
srvs << { :uri => u, :reconnect_attempts => 0 }
|
683
|
+
srvs << { :uri => u, :reconnect_attempts => 0, :discovered => true }
|
684
684
|
end
|
685
685
|
end
|
686
686
|
srvs.shuffle! unless @options[:dont_randomize_servers]
|
@@ -810,7 +810,14 @@ module NATS
|
|
810
810
|
end
|
811
811
|
|
812
812
|
def should_delay_connect?(server)
|
813
|
-
|
813
|
+
case
|
814
|
+
when server[:was_connected]
|
815
|
+
server[:reconnect_attempts] >= 0
|
816
|
+
when server[:last_reconnect_attempt]
|
817
|
+
(MonotonicTime.now - server[:last_reconnect_attempt]) < @options[:reconnect_time_wait]
|
818
|
+
else
|
819
|
+
false
|
820
|
+
end
|
814
821
|
end
|
815
822
|
|
816
823
|
def schedule_reconnect #:nodoc:
|
@@ -823,7 +830,7 @@ module NATS
|
|
823
830
|
# Allow notifying from which server we were disconnected,
|
824
831
|
# but only when we didn't trigger disconnecting ourselves.
|
825
832
|
if @disconnect_cb and connected? and not closing?
|
826
|
-
disconnect_cb.call(NATS::ConnectError.new(disconnect_error_string))
|
833
|
+
@disconnect_cb.call(NATS::ConnectError.new(disconnect_error_string))
|
827
834
|
end
|
828
835
|
|
829
836
|
# If we are closing or shouldn't reconnect, go ahead and disconnect.
|
@@ -889,6 +896,10 @@ module NATS
|
|
889
896
|
def attempt_reconnect #:nodoc:
|
890
897
|
@reconnect_timer = nil
|
891
898
|
current = server_pool.first
|
899
|
+
|
900
|
+
# Snapshot time when trying to reconnect to server
|
901
|
+
# in order to back off for subsequent attempts.
|
902
|
+
current[:last_reconnect_attempt] = MonotonicTime.now
|
892
903
|
current[:reconnect_attempts] ||= 0
|
893
904
|
current[:reconnect_attempts] += 1
|
894
905
|
|
@@ -934,6 +945,12 @@ module NATS
|
|
934
945
|
connected? ? @uri : nil
|
935
946
|
end
|
936
947
|
|
948
|
+
# Retrieves the list of servers which have been discovered
|
949
|
+
# via server connect_urls announcements
|
950
|
+
def discovered_servers
|
951
|
+
server_pool.select {|s| s[:discovered] }
|
952
|
+
end
|
953
|
+
|
937
954
|
def bind_primary #:nodoc:
|
938
955
|
first = server_pool.first
|
939
956
|
@uri = first[:uri]
|
@@ -974,4 +991,23 @@ module NATS
|
|
974
991
|
"<nats client v#{NATS::VERSION}>"
|
975
992
|
end
|
976
993
|
|
994
|
+
class MonotonicTime
|
995
|
+
class << self
|
996
|
+
case
|
997
|
+
when defined?(Process::CLOCK_MONOTONIC)
|
998
|
+
def now
|
999
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
1000
|
+
end
|
1001
|
+
when RUBY_ENGINE == 'jruby'
|
1002
|
+
def now
|
1003
|
+
java.lang.System.nanoTime() / 1_000_000_000.0
|
1004
|
+
end
|
1005
|
+
else
|
1006
|
+
def now
|
1007
|
+
# Fallback to regular time behavior
|
1008
|
+
::Time.now.to_f
|
1009
|
+
end
|
1010
|
+
end
|
1011
|
+
end
|
1012
|
+
end
|
977
1013
|
end
|
data/lib/nats/version.rb
CHANGED
data/nats.gemspec
CHANGED
@@ -16,7 +16,7 @@ spec = Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.authors = ['Derek Collison']
|
18
18
|
s.email = ['derek.collison@gmail.com']
|
19
|
-
s.add_dependency('eventmachine', '~> 1.2', '>= 1.2
|
19
|
+
s.add_dependency('eventmachine', '~> 1.2', '>= 1.2')
|
20
20
|
|
21
21
|
s.require_paths = ['lib']
|
22
22
|
s.bindir = 'bin'
|
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
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Collison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '1.2'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.2
|
22
|
+
version: '1.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '1.2'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.2
|
32
|
+
version: '1.2'
|
33
33
|
description: NATS is an open-source, high-performance, lightweight cloud messaging
|
34
34
|
system.
|
35
35
|
email:
|