nsq-ruby 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f37fc34c90bdbfed9f8f653ebb360f3449f2b617
4
- data.tar.gz: b10cf00412546004c46e2c620671b565c405b107
3
+ metadata.gz: cbfb90bdb3cd20d66a806966a6b3eda69128da2d
4
+ data.tar.gz: 34768fbb3f8146dd971c24cf14e8f8a6eb33dc5a
5
5
  SHA512:
6
- metadata.gz: 5fb3324959318b2b7f7be1ab989ddfe521dfee92eb7e9a2a3e002d611904c44f38d42da8a57f29baed4d80d477f9ddc37bc884008a21920378dfb41db3c0d657
7
- data.tar.gz: 17a7c36cd9f9a245183af03cf73a3a027df5028c151399780e102494bf1db61ae46f85f500eb1e1e70ff609c4e6159e28d0f9c85cd55feac51121f86af5d98c9
6
+ metadata.gz: baffdc2899b758231cd9cece73b598114d826bd18ca4bc909873f353884dd0ca15f5c6f612ad6dd5b6cf032a283c9f080df992cd9d264a28c4d6a5474bd4d89a
7
+ data.tar.gz: 16eec84732c35cca1adafa34b4ecd6cb08ced46f534977fd801552d5ca3f28e82853ce7427e100ad5a180693eeac3f1beac04c996fef87a597c10fdd120f15b3
data/README.md CHANGED
@@ -234,7 +234,7 @@ Nsq.logger = Logger.new(STDOUT)
234
234
 
235
235
  ## Requirements
236
236
 
237
- NSQ v0.2.29 or later due for IDENTITY metadata specification (0.2.28) and per-
237
+ NSQ v0.2.29 or later for IDENTIFY metadata specification (0.2.28) and per-
238
238
  connection timeout support (0.2.29).
239
239
 
240
240
 
@@ -244,6 +244,7 @@ connection timeout support (0.2.29).
244
244
  - Automatic reconnection to nsqd
245
245
  - Producing to all nsqd instances automatically via nsqlookupd
246
246
 
247
+
247
248
  ### Does not support
248
249
 
249
250
  - TLS
@@ -137,21 +137,12 @@ module Nsq
137
137
  end
138
138
 
139
139
 
140
- # Block until we get an OK from nsqd
141
- def wait_for_ok
142
- frame = receive_frame
143
- unless frame.is_a?(Response) && frame.data == RESPONSE_OK
144
- raise "Received non-OK response while IDENTIFYing: #{frame.data}"
145
- end
146
- end
147
-
148
-
149
140
  def identify
150
141
  hostname = Socket.gethostname
151
142
  metadata = {
152
143
  client_id: Socket.gethostbyname(hostname).flatten.compact.first,
153
144
  hostname: hostname,
154
- feature_negotiation: false,
145
+ feature_negotiation: true,
155
146
  heartbeat_interval: 30_000, # 30 seconds
156
147
  output_buffer: 16_000, # 16kb
157
148
  output_buffer_timeout: 250, # 250ms
@@ -163,6 +154,16 @@ module Nsq
163
154
  msg_timeout: @msg_timeout
164
155
  }.to_json
165
156
  write_to_socket ["IDENTIFY\n", metadata.length, metadata].pack('a*l>a*')
157
+
158
+ # Now wait for the response!
159
+ frame = receive_frame
160
+ server = JSON.parse(frame.data)
161
+
162
+ if @max_in_flight > server['max_rdy_count']
163
+ raise "max_in_flight is set to #{@max_in_flight}, server only supports #{server['max_rdy_count']}"
164
+ end
165
+
166
+ @server_version = server['version']
166
167
  end
167
168
 
168
169
 
@@ -199,10 +200,11 @@ module Nsq
199
200
  def decrement_in_flight
200
201
  @presumed_in_flight -= 1
201
202
 
202
- # now that we're less than @max_in_flight we might need to re-up our RDY
203
- # state
204
- threshold = (@max_in_flight * 0.2).ceil
205
- re_up_ready if @presumed_in_flight <= threshold
203
+ if server_needs_rdy_re_ups?
204
+ # now that we're less than @max_in_flight we might need to re-up our RDY state
205
+ threshold = (@max_in_flight * 0.2).ceil
206
+ re_up_ready if @presumed_in_flight <= threshold
207
+ end
206
208
  end
207
209
 
208
210
 
@@ -312,7 +314,6 @@ module Nsq
312
314
  # it gets to nsqd ahead of anything in the `@write_queue`
313
315
  write_to_socket ' V2'
314
316
  identify
315
- wait_for_ok
316
317
 
317
318
  start_read_loop
318
319
  start_write_loop
@@ -387,5 +388,14 @@ module Nsq
387
388
  def snooze(t)
388
389
  sleep(t)
389
390
  end
391
+
392
+
393
+ def server_needs_rdy_re_ups?
394
+ # versions less than 0.3.0 need RDY re-ups
395
+ # see: https://github.com/bitly/nsq/blob/master/ChangeLog.md#030---2014-11-18
396
+ @server_version.split('.')[0].to_i == 0 && @server_version.split('.')[1].to_i <= 2
397
+ end
398
+
399
+
390
400
  end
391
401
  end
data/lib/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Nsq
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsq-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wistia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler