nsq-ruby 1.7.0 → 2.0.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: 7330baaeb160c2c5d5771c6694c67fd431b635b9
4
- data.tar.gz: 69ab28adb8065ba95d8a6936fc6f437c8b28d1d7
3
+ metadata.gz: 6cbb0662845f5a7d8080d9531d9238fe12b8f87e
4
+ data.tar.gz: 105520f8192afccdba5097cae209ac36d1ec09e9
5
5
  SHA512:
6
- metadata.gz: ebb0f048f870b45ff0123406639b2cb824bd69e4db938efeaa1751fb60de78e2477864f55eab890ad919efc8cbe1da10a290d8d152f3c989b7697116c40cf04d
7
- data.tar.gz: 5fd65ab036ffdef8d0460b839a358e93b19849668f007fe22f8d1ded73a781408faf32e4147f7c354c11cc113357e9e716e39d14070cc55c3ee7cb446e0f98bd
6
+ metadata.gz: 7b4038559f24a0923af28a5e9c0281f32f09850b3970b07c52abd587d66dd119d912686408f91e92c77d376c5565d73a8bfcf3c9f391bacde6e22ce550f10d0b
7
+ data.tar.gz: d0425623eb3cf5733e5b10bc2ab40bb377c9fa4e5ecf9509e5ea88d4006f64211cda36821165b696ab7b58fb139c6aa39ceb12001229f92fd1e5d8e0f5296895
data/README.md CHANGED
@@ -68,8 +68,9 @@ The Nsq::Producer constructor takes the following options:
68
68
  |---------------|----------------------------------------|--------------------|
69
69
  | `topic` | Topic to which to publish messages | |
70
70
  | `nsqd` | Host and port of the nsqd instance | '127.0.0.1:4150' |
71
- | `nsqlookupd` | Use lookupd to automatically discover nsqds | |
72
- | `ssl_context` | Optional keys and certificates for TLS connections | |
71
+ | `nsqlookupd` | Use lookupd to auto discover nsqds | |
72
+ | `tls_v1` | Flag for tls v1 connections | false |
73
+ | `tls_options` | Optional keys+certs for TLS connections| |
73
74
 
74
75
  For example, if you'd like to publish messages to a single nsqd.
75
76
 
@@ -92,19 +93,29 @@ producer = Nsq::Producer.new(
92
93
  )
93
94
  ```
94
95
 
95
- If you need to connect using SSL/TLS
96
+ If you need to connect using SSL/TLS Authentication via `tls_options`
96
97
 
97
98
  ```Ruby
98
99
  producer = Nsq::Producer.new(
99
100
  nsqlookupd: ['1.2.3.4:4161', '6.7.8.9:4161'],
100
101
  topic: 'topic-of-great-esteem',
101
- ssl_context: {
102
+ tls_v1: true,
103
+ tls_options: {
102
104
  key: '/path/to/ssl/key.pem',
103
105
  certificate: '/path/to/ssl/certificate.pem'
104
106
  }
105
107
  )
106
108
  ```
107
109
 
110
+ If you need to connect using simple `tls_v1`
111
+
112
+ ```Ruby
113
+ producer = Nsq::Producer.new(
114
+ nsqlookupd: ['1.2.3.4:4161', '6.7.8.9:4161'],
115
+ topic: 'topic-of-great-esteem',
116
+ tls_v1: true
117
+ )
118
+ ```
108
119
 
109
120
  ### `#write`
110
121
 
@@ -170,9 +181,10 @@ producers when you're done with them.
170
181
  | `nsqlookupd` | Use lookupd to automatically discover nsqds | |
171
182
  | `nsqd` | Connect directly to a single nsqd instance | '127.0.0.1:4150' |
172
183
  | `max_in_flight` | Max number of messages for this consumer to have in flight at a time | 1 |
173
- | `discovery_interval` | Seconds between queue discovery via nsqlookupd | 60.0 |
174
- | `msg_timeout` | Milliseconds before nsqd will timeout a message | 60000 |
175
- | `ssl_context` | Optional keys and certificates for TLS connections | |
184
+ | `discovery_interval` | Seconds between queue discovery via nsqlookupd | 60.0 |
185
+ | `msg_timeout` | Milliseconds before nsqd will timeout a message | 60000 |
186
+ | `tls_v1` | Flag for tls v1 connections | false |
187
+ | `tls_options` | Optional keys and certificates for TLS connections | |
176
188
 
177
189
 
178
190
  For example:
@@ -185,7 +197,8 @@ consumer = Nsq::Consumer.new(
185
197
  max_in_flight: 100,
186
198
  discovery_interval: 30,
187
199
  msg_timeout: 120_000,
188
- ssl_context: {
200
+ tls_v1: true,
201
+ tls_options: {
189
202
  key: '/path/to/ssl/key.pem',
190
203
  certificate: '/path/to/ssl/certificate.pem'
191
204
  }
@@ -90,7 +90,9 @@ module Nsq
90
90
  connection = Connection.new({
91
91
  host: host,
92
92
  port: port,
93
- ssl_context: @ssl_context
93
+ ssl_context: @ssl_context,
94
+ tls_options: @tls_options,
95
+ tls_v1: @tls_v1
94
96
  }.merge(options))
95
97
  @connections[nsqd] = connection
96
98
  end
@@ -31,8 +31,24 @@ module Nsq
31
31
  @channel = opts[:channel]
32
32
  @msg_timeout = opts[:msg_timeout] || 60_000 # 60s
33
33
  @max_in_flight = opts[:max_in_flight] || 1
34
- @ssl_context = opts[:ssl_context]
35
- validate_ssl_context! if @ssl_context
34
+ @tls_options = opts[:tls_options]
35
+ if opts[:ssl_context]
36
+ if @tls_options
37
+ warn 'ssl_context and tls_options both set. Using tls_options. Ignoring ssl_context.'
38
+ else
39
+ @tls_options = opts[:ssl_context]
40
+ warn 'ssl_context will be deprecated nsq-ruby version 3. Please use tls_options instead.'
41
+ end
42
+ end
43
+ @tls_v1 = !!opts[:tls_v1]
44
+
45
+ if @tls_options
46
+ if @tls_v1
47
+ validate_tls_options!
48
+ else
49
+ warn 'tls_options was provided, but tls_v1 is false. Skipping validation of tls_options.'
50
+ end
51
+ end
36
52
 
37
53
  if @msg_timeout < 1000
38
54
  raise ArgumentError, 'msg_timeout cannot be less than 1000. it\'s in milliseconds.'
@@ -152,7 +168,7 @@ module Nsq
152
168
  heartbeat_interval: 30_000, # 30 seconds
153
169
  output_buffer: 16_000, # 16kb
154
170
  output_buffer_timeout: 250, # 250ms
155
- tls_v1: !!@ssl_context,
171
+ tls_v1: @tls_v1,
156
172
  snappy: false,
157
173
  deflate: false,
158
174
  sample_rate: 0, # disable sampling
@@ -320,7 +336,7 @@ module Nsq
320
336
  # it gets to nsqd ahead of anything in the `@write_queue`
321
337
  write_to_socket ' V2'
322
338
  identify
323
- upgrade_to_ssl_socket if @ssl_context
339
+ upgrade_to_ssl_socket if @tls_v1
324
340
 
325
341
  start_read_loop
326
342
  start_write_loop
@@ -354,17 +370,20 @@ module Nsq
354
370
 
355
371
 
356
372
  def upgrade_to_ssl_socket
357
- @socket = OpenSSL::SSL::SSLSocket.new(@socket, openssl_context)
373
+ ssl_opts = [@socket, openssl_context].compact
374
+ @socket = OpenSSL::SSL::SSLSocket.new(*ssl_opts)
358
375
  @socket.connect
359
376
  end
360
377
 
361
378
 
362
379
  def openssl_context
380
+ return unless @tls_options
381
+
363
382
  context = OpenSSL::SSL::SSLContext.new
364
- context.cert = OpenSSL::X509::Certificate.new(File.open(@ssl_context[:certificate]))
365
- context.key = OpenSSL::PKey::RSA.new(File.open(@ssl_context[:key]))
366
- if @ssl_context[:ca_certificate]
367
- context.ca_file = OpenSSL::X509::Certificate.new(File.open(@ssl_context[:ca_certificate])).to_pem
383
+ context.cert = OpenSSL::X509::Certificate.new(File.open(@tls_options[:certificate]))
384
+ context.key = OpenSSL::PKey::RSA.new(File.open(@tls_options[:key]))
385
+ if @tls_options[:ca_certificate]
386
+ context.ca_file = OpenSSL::X509::Certificate.new(File.open(@tls_options[:ca_certificate])).to_pem
368
387
  end
369
388
  context
370
389
  end
@@ -422,16 +441,16 @@ module Nsq
422
441
  end
423
442
 
424
443
 
425
- def validate_ssl_context!
444
+ def validate_tls_options!
426
445
  [:key, :certificate].each do |key|
427
- unless @ssl_context.has_key?(key)
428
- raise ArgumentError.new "ssl_context requires a :#{key}"
446
+ unless @tls_options.has_key?(key)
447
+ raise ArgumentError.new "@tls_options requires a :#{key}"
429
448
  end
430
449
  end
431
450
 
432
451
  [:key, :certificate, :ca_certificate].each do |key|
433
- if @ssl_context[key] && !File.readable?(@ssl_context[key])
434
- raise LoadError.new "ssl_context :#{key} is unreadable"
452
+ if @tls_options[key] && !File.readable?(@tls_options[key])
453
+ raise LoadError.new "@tls_options :#{key} is unreadable"
435
454
  end
436
455
  end
437
456
  end
data/lib/nsq/consumer.rb CHANGED
@@ -18,6 +18,8 @@ module Nsq
18
18
  @discovery_interval = opts[:discovery_interval] || 60
19
19
  @msg_timeout = opts[:msg_timeout]
20
20
  @ssl_context = opts[:ssl_context]
21
+ @tls_options = opts[:tls_options]
22
+ @tls_v1 = opts[:tls_v1]
21
23
 
22
24
  # This is where we queue up the messages we receive from each connection
23
25
  @messages = opts[:queue] || Queue.new
data/lib/nsq/producer.rb CHANGED
@@ -9,6 +9,8 @@ module Nsq
9
9
  @topic = opts[:topic]
10
10
  @discovery_interval = opts[:discovery_interval] || 60
11
11
  @ssl_context = opts[:ssl_context]
12
+ @tls_options = opts[:tls_options]
13
+ @tls_v1 = opts[:tls_v1]
12
14
 
13
15
  nsqlookupds = []
14
16
  if opts[:nsqlookupd]
data/lib/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Nsq
2
2
  module Version
3
- MAJOR = 1
4
- MINOR = 7
3
+ MAJOR = 2
4
+ MINOR = 0
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.7.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wistia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-28 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 2.2.2
112
+ rubygems_version: 2.5.1
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Ruby client library for NSQ