nats 0.4.8 → 0.4.10

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.
data/lib/nats/client.rb CHANGED
@@ -8,7 +8,7 @@ require "#{ep}/ext/json"
8
8
 
9
9
  module NATS
10
10
 
11
- VERSION = "0.4.8".freeze
11
+ VERSION = "0.4.10".freeze
12
12
 
13
13
  DEFAULT_PORT = 4222
14
14
  DEFAULT_URI = "nats://localhost:#{DEFAULT_PORT}".freeze
@@ -53,6 +53,14 @@ module NATS
53
53
  class Error < StandardError #:nodoc:
54
54
  end
55
55
 
56
+ # When the NATS server sends us an ERROR message, this is raised/passed by default
57
+ class ServerError < Error #:nodoc:
58
+ end
59
+
60
+ # When we cannot connect to the server (either initially or after a reconnect), this is raised/passed
61
+ class ConnectError < Error #:nodoc:
62
+ end
63
+
56
64
  class << self
57
65
  attr_reader :client, :reactor_was_running, :err_cb, :err_cb_overridden #:nodoc:
58
66
  attr_accessor :timeout_cb #:nodoc
@@ -84,7 +92,7 @@ module NATS
84
92
  opts[:pedantic] = ENV['NATS_PEDANTIC'] unless ENV['NATS_PEDANTIC'].nil?
85
93
  opts[:debug] = ENV['NATS_DEBUG'] if !ENV['NATS_DEBUG'].nil?
86
94
  @uri = opts[:uri] = URI.parse(opts[:uri])
87
- @err_cb = proc { raise Error, "Could not connect to server on #{@uri}."} unless err_cb
95
+ @err_cb = proc {|e| raise e } unless err_cb
88
96
  check_autostart(@uri) if opts[:autostart] == true
89
97
 
90
98
  client = EM.connect(@uri.host, @uri.port, self, opts)
@@ -402,8 +410,7 @@ module NATS
402
410
  @buf = $'
403
411
  when ERR
404
412
  @buf = $'
405
- @err_cb = proc { raise Error, "Error received from server :#{$1}."} unless user_err_cb?
406
- err_cb.call($1)
413
+ err_cb.call(NATS::ServerError.new($1))
407
414
  when PING
408
415
  @buf = $'
409
416
  send_command(PONG_RESPONSE)
@@ -416,8 +423,7 @@ module NATS
416
423
  process_info($1)
417
424
  when UNKNOWN
418
425
  @buf = $'
419
- @err_cb = proc { raise Error, "Error: Ukknown Protocol."} unless user_err_cb?
420
- err_cb.call($1)
426
+ err_cb.call(NATS::Error.new("Unknown protocol: $1"))
421
427
  else
422
428
  # If we are here we do not have a complete line yet that we understand.
423
429
  return
@@ -448,7 +454,7 @@ module NATS
448
454
  end
449
455
  flush_pending if @pending
450
456
  unless user_err_cb? or reconnecting?
451
- @err_cb = proc { raise Error, "Client disconnected from server on #{@uri}."}
457
+ @err_cb = proc {|e| raise e }
452
458
  end
453
459
  if (connect_cb and not reconnecting?)
454
460
  # We will round trip the server here to make sure all state from any pending commands
@@ -476,7 +482,7 @@ module NATS
476
482
  def process_disconnect #:nodoc:
477
483
  if not closing? and @err_cb
478
484
  err_string = @connected ? "Client disconnected from server on #{@uri}." : "Could not connect to server on #{@uri}"
479
- err_cb.call(err_string)
485
+ err_cb.call(NATS::ConnectError.new(err_string))
480
486
  end
481
487
  ensure
482
488
  EM.cancel_timer(@reconnect_timer) if @reconnect_timer
@@ -1,7 +1,7 @@
1
1
 
2
2
  module NATSD #:nodoc:
3
3
 
4
- VERSION = '0.4.8'
4
+ VERSION = '0.4.10'
5
5
  APP_NAME = 'nats-server'
6
6
 
7
7
  DEFAULT_PORT = 4222
@@ -109,8 +109,9 @@ module NATSD #:nodoc: all
109
109
  trace("Matched queue subscriber", sub[:subject], sub[:qgroup], sub[:sid], sub.conn.client_info)
110
110
  end
111
111
  # Queue this for post processing
112
- qsubs ||= Hash.new([])
113
- qsubs[sub[:qgroup]] = qsubs[sub[:qgroup]] << sub
112
+ qsubs ||= Hash.new
113
+ qsubs[sub[:qgroup]] ||= []
114
+ qsubs[sub[:qgroup]] << sub
114
115
  end
115
116
  end
116
117
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: nats
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.8
5
+ version: 0.4.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - Derek Collison
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-02 00:00:00 -05:00
13
+ date: 2011-04-21 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency