nats 0.5.1 → 0.6.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
  SHA1:
3
- metadata.gz: bdd90752229d1b9e8958d4a29b02951ce3107d93
4
- data.tar.gz: 0f7ddb25822e6be88d025d8a1ab200470b7c5a2f
3
+ metadata.gz: 9001307af28148c669590f0964512c8ddc60cff4
4
+ data.tar.gz: 97ffb35dca621454dddcda8aad90d081b7d51520
5
5
  SHA512:
6
- metadata.gz: c0543c590534e277b2b95077d564acdc0055478e04655fa24030022f34bd14bd0a7fd5450288c89984106f0832d68088053fdec3555a3f6bf6c4f0630efdfb2c
7
- data.tar.gz: 9207aac064c91db634a100a01f482696ffa0362ce257ab44661c921b9fab408206009fc082fd20ade7c67521c625b36ae1a7d1d278c8d70b6645177b9687f5cd
6
+ metadata.gz: a2aaddd687461480f22bd596d60d1b28cf10af716d011d2531e9e7f31f6b5391c9e67f33f494378c8d39c7973ae426bce6e93227e8ce65ec30d3988d045f02f1
7
+ data.tar.gz: 446229594e7a0f4aa88aba27e5e3f12abe8adffdde363674a7e464ed541567ed81370ef939a25c77d455051407078fd6dce73f89d310bb5e0bd5637c7e2b5032
data/HISTORY.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # HISTORY
2
2
 
3
+ ## v0.6.0 (March 22, 2016)
4
+ - Removed distributing `nats-server` along with the gem
5
+ - Fixed issue with subscriptions not being sent on first reconnect (#94)
6
+ - Added loading Oj gem for JSON when supported (#91)
7
+ - Fixed removing warning message introduced by EM 1.0.8 (#90)
8
+ - Changed to testing spec with `gnatsd` (#95)
9
+ - See full list @ https://github.com/nats-io/ruby-nats/compare/v0.5.1...v0.6.0
10
+
11
+ ## v0.5.1 (August 7, 2015)
12
+ - Changed to never remove servers when configured as such (#88)
13
+ - See full list @ https://github.com/nats-io/ruby-nats/compare/v0.5.0...v0.5.1
14
+
15
+ ## v0.5.0 (June 19, 2015)
16
+ - See full list @ https://github.com/nats-io/ruby-nats/compare/v0.5.0.beta.16...v0.5.0
17
+
3
18
  ## v0.5.0.beta.16 (December 7, 2014)
4
19
  - Resolved major issue on cluster connects to non-first server, issue #78
5
20
  - Official Support for Ruby 2.1
data/Rakefile CHANGED
@@ -1,12 +1,26 @@
1
- desc "Run rspec"
2
- task :spec do
3
- require "rspec/core/rake_task"
4
- RSpec::Core::RakeTask.new do |t|
5
- t.rspec_opts = %w(-fd -c)
6
- end
1
+ #!/usr/bin/env rake
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Run specs from client and server'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ spec.rspec_opts = ["--format", "documentation", "--colour"]
7
9
  end
8
10
  task :default => :spec
9
11
 
12
+ desc 'Run spec from client using gnatsd as the server'
13
+ RSpec::Core::RakeTask.new('spec:client') do |spec|
14
+ spec.pattern = FileList['spec/client/*_spec.rb']
15
+ spec.rspec_opts = ["--format", "documentation", "--colour"]
16
+ end
17
+
18
+ desc 'Run spec from server'
19
+ RSpec::Core::RakeTask.new('spec:server') do |spec|
20
+ spec.pattern = FileList['spec/server/*_spec.rb']
21
+ spec.rspec_opts = ["--format", "documentation", "--colour"]
22
+ end
23
+
10
24
  desc "Build the gem"
11
25
  task :gem do
12
26
  sh 'gem build *.gemspec'
@@ -6,11 +6,10 @@ ep = File.expand_path(File.dirname(__FILE__))
6
6
  require "#{ep}/ext/em"
7
7
  require "#{ep}/ext/bytesize"
8
8
  require "#{ep}/ext/json"
9
+ require "#{ep}/version"
9
10
 
10
11
  module NATS
11
12
 
12
- VERSION = "0.5.1".freeze
13
-
14
13
  DEFAULT_PORT = 4222
15
14
  DEFAULT_URI = "nats://localhost:#{DEFAULT_PORT}".freeze
16
15
 
@@ -43,6 +42,7 @@ module NATS
43
42
  PING_REQUEST = ("PING#{CR_LF}".freeze) #:nodoc:
44
43
  PONG_RESPONSE = ("PONG#{CR_LF}".freeze) #:nodoc:
45
44
 
45
+ SUB_OP = ('SUB'.freeze) #:nodoc:
46
46
  EMPTY_MSG = (''.freeze) #:nodoc:
47
47
 
48
48
  # Used for future pedantic Mode
@@ -53,13 +53,6 @@ module NATS
53
53
  AWAITING_CONTROL_LINE = 1 #:nodoc:
54
54
  AWAITING_MSG_PAYLOAD = 2 #:nodoc:
55
55
 
56
- # Autostart properties
57
- AUTOSTART_PID_FILE = '/tmp/nats-server.pid'
58
- AUTOSTART_LOG_FILE = '/tmp/nats-server.log'
59
-
60
- # Duplicate autostart protection
61
- @@tried_autostart = {}
62
-
63
56
  class Error < StandardError; end #:nodoc:
64
57
 
65
58
  # When the NATS server sends us an ERROR message, this is raised/passed by default
@@ -82,12 +75,10 @@ module NATS
82
75
  alias :reactor_was_running? :reactor_was_running
83
76
 
84
77
  # Create and return a connection to the server with the given options.
85
- # The server will be autostarted if requested and the <b>uri</b> is determined to be local.
86
78
  # The optional block will be called when the connection has been completed.
87
79
  #
88
80
  # @param [Hash] opts
89
81
  # @option opts [String|URI] :uri The URI to connect to, example nats://localhost:4222
90
- # @option opts [Boolean] :autostart Boolean that can be used to engage server autostart functionality.
91
82
  # @option opts [Boolean] :reconnect Boolean that can be used to suppress reconnect functionality.
92
83
  # @option opts [Boolean] :debug Boolean that can be used to output additional debug information.
93
84
  # @option opts [Boolean] :verbose Boolean that is sent to server for setting verbose protocol mode.
@@ -136,7 +127,6 @@ module NATS
136
127
  end
137
128
 
138
129
  @err_cb = proc { |e| raise e } unless err_cb
139
- check_autostart(@uri) if opts[:autostart] == true
140
130
 
141
131
  client = EM.connect(@uri.host, @uri.port, self, opts)
142
132
  client.on_connect(&blk) if blk
@@ -151,7 +141,13 @@ module NATS
151
141
  raise(Error, "EM needs to be running when NATS.start is called without a run block")
152
142
  end
153
143
  # Setup optimized select versions
154
- EM.epoll; EM.kqueue
144
+ if EM.epoll?
145
+ EM.epoll
146
+ elsif EM.kqueue?
147
+ EM.kqueue
148
+ else
149
+ Kernel.warn('Neither epoll nor kqueue are supported')
150
+ end
155
151
  EM.run { @client = connect(*args, &blk) }
156
152
  end
157
153
 
@@ -160,7 +156,6 @@ module NATS
160
156
  def stop(&blk)
161
157
  client.close if (client and (client.connected? || client.reconnecting?))
162
158
  blk.call if blk
163
- @@tried_autostart = {}
164
159
  @err_cb = nil
165
160
  end
166
161
 
@@ -278,29 +273,10 @@ module NATS
278
273
 
279
274
  private
280
275
 
281
- def check_autostart(uri)
282
- return if uri_is_remote?(uri) || @@tried_autostart[uri]
283
- @@tried_autostart[uri] = true
284
- return if server_running?(uri)
285
- return unless try_autostart_succeeded?(uri)
286
- wait_for_server(uri)
287
- end
288
-
289
276
  def uri_is_remote?(uri)
290
277
  uri.host != 'localhost' && uri.host != '127.0.0.1'
291
278
  end
292
279
 
293
- def try_autostart_succeeded?(uri)
294
- port_arg = "-p #{uri.port}"
295
- user_arg = "--user #{uri.user}" if uri.user
296
- pass_arg = "--pass #{uri.password}" if uri.password
297
- log_arg = "-l #{AUTOSTART_LOG_FILE}"
298
- pid_arg = "-P #{AUTOSTART_PID_FILE}"
299
- # daemon mode to release client
300
- `nats-server #{port_arg} #{user_arg} #{pass_arg} #{log_arg} #{pid_arg} -d 2> /dev/null`
301
- $? == 0
302
- end
303
-
304
280
  end
305
281
 
306
282
  attr_reader :connected, :connect_cb, :err_cb, :err_cb_overridden, :pongs_received #:nodoc:
@@ -314,7 +290,9 @@ module NATS
314
290
  def initialize(options)
315
291
  @options = options
316
292
  process_uri_options
293
+ @ssl = false
317
294
  @ssl = options[:ssl] if options[:ssl]
295
+ @buf = nil
318
296
  @ssid, @subs = 1, {}
319
297
  @err_cb = NATS.err_cb
320
298
  @reconnect_timer, @needed = nil, nil
@@ -584,7 +562,11 @@ module NATS
584
562
  end
585
563
 
586
564
  def process_info(info) #:nodoc:
587
- @server_info = JSON.parse(info, :symbolize_keys => true, :symbolize_names => true)
565
+ # Each JSON parser uses a different key/value pair to use symbol keys
566
+ # instead of strings when parsing. Passing all three pairs assures each
567
+ # parser gets what it needs. For the json gem :symbolize_name, for yajl
568
+ # :symbolize_keys, and for oj :symbol_keys.
569
+ @server_info = JSON.parse(info, :symbolize_keys => true, :symbolize_names => true, :symbol_keys => true)
588
570
  if @server_info[:ssl_required] && @ssl
589
571
  start_tls
590
572
  else
@@ -621,11 +603,12 @@ module NATS
621
603
  current = server_pool.first
622
604
  current[:was_connected] = true
623
605
  current[:reconnect_attempts] = 0
606
+ cancel_reconnect_timer if reconnecting?
624
607
 
625
- if reconnecting?
626
- cancel_reconnect_timer
627
- @subs.each_pair { |k, v| send_command("SUB #{v[:subject]} #{v[:queue]} #{k}#{CR_LF}") }
628
- end
608
+ # whip through any pending SUB commands since we replay
609
+ # all subscriptions already done anyway.
610
+ @pending.delete_if { |sub| sub[0..2] == SUB_OP }
611
+ @subs.each_pair { |k, v| send_command("SUB #{v[:subject]} #{v[:queue]} #{k}#{CR_LF}") }
629
612
 
630
613
  unless user_err_cb? or reconnecting?
631
614
  @err_cb = proc { |e| raise e }
@@ -2,6 +2,11 @@ begin
2
2
  require 'yajl'
3
3
  require 'yajl/json_gem'
4
4
  rescue LoadError
5
- require 'rubygems'
6
- require 'json'
5
+ begin
6
+ require 'oj'
7
+ Oj.mimic_JSON()
8
+ rescue LoadError
9
+ require 'rubygems'
10
+ require 'json'
11
+ end
7
12
  end
@@ -26,7 +26,7 @@ NATSD::Server.setup(ARGV.dup)
26
26
  # Event Loop
27
27
  EM.run do
28
28
 
29
- log "WARNING: nats-server is deprecated and no longer supported. It will be removed in a future release. See https://github.com/apcera/gnatsd."
29
+ log "WARNING: nats-server is deprecated and no longer supported. It will be removed in a future release. See https://github.com/nats-io/gnatsd"
30
30
  log "Starting #{NATSD::APP_NAME} version #{NATSD::VERSION} on port #{NATSD::Server.port}"
31
31
  log "TLS/SSL Support Enabled" if NATSD::Server.options[:ssl]
32
32
  begin
@@ -20,7 +20,8 @@ module NATSD #:nodoc: all
20
20
  end
21
21
 
22
22
  def client_info
23
- @client_info ||= (get_peername.nil? ? 'N/A' : Socket.unpack_sockaddr_in(get_peername))
23
+ cur_peername = get_peername
24
+ @client_info ||= (cur_peername.nil? ? 'N/A' : Socket.unpack_sockaddr_in(cur_peername))
24
25
  end
25
26
 
26
27
  def info
@@ -0,0 +1,3 @@
1
+ module NATS
2
+ VERSION = "0.6.0".freeze
3
+ end
@@ -3,11 +3,11 @@
3
3
  lib = File.expand_path('../lib/', __FILE__)
4
4
  $:.unshift lib unless $:.include?(lib)
5
5
 
6
- require 'nats/server/const'
6
+ require 'nats/version'
7
7
 
8
8
  spec = Gem::Specification.new do |s|
9
9
  s.name = 'nats'
10
- s.version = NATSD::VERSION
10
+ s.version = NATS::VERSION
11
11
  s.summary = 'NATS is an open-source, high-performance, lightweight cloud messaging system.'
12
12
  s.homepage = 'https://nats.io'
13
13
  s.description = 'NATS is an open-source, high-performance, lightweight cloud messaging system.'
@@ -24,7 +24,7 @@ spec = Gem::Specification.new do |s|
24
24
 
25
25
  s.require_paths = ['lib']
26
26
  s.bindir = 'bin'
27
- s.executables = [NATSD::APP_NAME, 'nats-pub', 'nats-sub', 'nats-queue', 'nats-top', 'nats-request']
27
+ s.executables = ['nats-pub', 'nats-sub', 'nats-queue', 'nats-top', 'nats-request']
28
28
 
29
29
  s.files = %w[
30
30
  COPYING
@@ -39,6 +39,7 @@ spec = Gem::Specification.new do |s|
39
39
  bin/nats-top
40
40
  bin/nats-request
41
41
  lib/nats/client.rb
42
+ lib/nats/version.rb
42
43
  lib/nats/ext/bytesize.rb
43
44
  lib/nats/ext/em.rb
44
45
  lib/nats/ext/json.rb
@@ -55,4 +56,4 @@ spec = Gem::Specification.new do |s|
55
56
  lib/nats/server/connz.rb
56
57
  ]
57
58
 
58
- end
59
+ end
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.5.1
4
+ version: 0.6.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: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -95,7 +95,6 @@ description: NATS is an open-source, high-performance, lightweight cloud messagi
95
95
  email:
96
96
  - derek.collison@gmail.com
97
97
  executables:
98
- - nats-server
99
98
  - nats-pub
100
99
  - nats-sub
101
100
  - nats-queue
@@ -129,6 +128,7 @@ files:
129
128
  - lib/nats/server/sublist.rb
130
129
  - lib/nats/server/util.rb
131
130
  - lib/nats/server/varz.rb
131
+ - lib/nats/version.rb
132
132
  - nats.gemspec
133
133
  homepage: https://nats.io
134
134
  licenses:
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.4.8
153
+ rubygems_version: 2.5.1
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: NATS is an open-source, high-performance, lightweight cloud messaging system.