nsq-ruby 1.5.1 → 1.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 +4 -4
- data/README.md +28 -7
- data/lib/nsq/client_base.rb +2 -1
- data/lib/nsq/connection.rb +36 -2
- data/lib/nsq/consumer.rb +1 -0
- data/lib/nsq/producer.rb +1 -0
- data/lib/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74c7cac5f391e1845369f6589a19a411781bcd5a
|
4
|
+
data.tar.gz: 87bff660b9a046e391cc5535eb05766c23d0ae41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 287c61b256fd4473c43ead39228423044eb936a6823195388488c5e058ae6908833cef0fa62e659afa97ef4606f53501ad521cf9337dca3c56ced373f5eb851b
|
7
|
+
data.tar.gz: 9eeb96b9dab4965e6b2df5910803117119e23b56b98ca3f5d871f7538ac487cac51cb17eb158f38aeaad62b87b35073936268beee9de2c8abcc80fff22e6804e
|
data/README.md
CHANGED
@@ -60,6 +60,7 @@ The Nsq::Producer constructor takes the following options:
|
|
60
60
|
| `topic` | Topic to which to publish messages | |
|
61
61
|
| `nsqd` | Host and port of the nsqd instance | '127.0.0.1:4150' |
|
62
62
|
| `nsqlookupd` | Use lookupd to automatically discover nsqds | |
|
63
|
+
| `ssl_context` | Optional keys and certificates for TLS connections | |
|
63
64
|
|
64
65
|
For example, if you'd like to publish messages to a single nsqd.
|
65
66
|
|
@@ -82,6 +83,19 @@ producer = Nsq::Producer.new(
|
|
82
83
|
)
|
83
84
|
```
|
84
85
|
|
86
|
+
If you need to connect using SSL/TLS
|
87
|
+
|
88
|
+
```Ruby
|
89
|
+
producer = Nsq::Producer.new(
|
90
|
+
nsqlookupd: ['1.2.3.4:4161', '6.7.8.9:4161'],
|
91
|
+
topic: 'topic-of-great-esteem',
|
92
|
+
ssl_context: {
|
93
|
+
key: '/path/to/ssl/key.pem',
|
94
|
+
certificate: '/path/to/ssl/certificate.pem'
|
95
|
+
}
|
96
|
+
)
|
97
|
+
```
|
98
|
+
|
85
99
|
|
86
100
|
### `#write`
|
87
101
|
|
@@ -149,6 +163,7 @@ producers when you're done with them.
|
|
149
163
|
| `max_in_flight` | Max number of messages for this consumer to have in flight at a time | 1 |
|
150
164
|
| `discovery_interval` | Seconds between queue discovery via nsqlookupd | 60.0 |
|
151
165
|
| `msg_timeout` | Milliseconds before nsqd will timeout a message | 60000 |
|
166
|
+
| `ssl_context` | Optional keys and certificates for TLS connections | |
|
152
167
|
|
153
168
|
|
154
169
|
For example:
|
@@ -160,7 +175,11 @@ consumer = Nsq::Consumer.new(
|
|
160
175
|
nsqlookupd: ['127.0.0.1:4161', '4.5.6.7:4161'],
|
161
176
|
max_in_flight: 100,
|
162
177
|
discovery_interval: 30,
|
163
|
-
msg_timeout: 120_000
|
178
|
+
msg_timeout: 120_000,
|
179
|
+
ssl_context: {
|
180
|
+
key: '/path/to/ssl/key.pem',
|
181
|
+
certificate: '/path/to/ssl/certificate.pem'
|
182
|
+
}
|
164
183
|
)
|
165
184
|
```
|
166
185
|
|
@@ -285,11 +304,11 @@ connection timeout support (0.2.29).
|
|
285
304
|
- Discovery via nsqlookupd
|
286
305
|
- Automatic reconnection to nsqd
|
287
306
|
- Producing to all nsqd instances automatically via nsqlookupd
|
307
|
+
- TLS
|
288
308
|
|
289
309
|
|
290
310
|
### Does not support
|
291
311
|
|
292
|
-
- TLS
|
293
312
|
- Compression
|
294
313
|
- Backoff
|
295
314
|
- Authentication
|
@@ -318,16 +337,18 @@ VERBOSE=true rake spec
|
|
318
337
|
## Is this production ready?
|
319
338
|
|
320
339
|
Yes! It's used in several critical parts of our infrastructure at
|
321
|
-
[Wistia](http://wistia.com) and currently produces and consumes
|
340
|
+
[Wistia](http://wistia.com) and currently produces and consumes hundreds of
|
322
341
|
millions of messages a day.
|
323
342
|
|
324
343
|
|
325
344
|
## Authors
|
326
345
|
|
327
|
-
- Robby Grossman (@freerobby)
|
328
|
-
- Brendan Schwartz (@bschwartz)
|
329
|
-
- Marshall Moutenot (@mmoutenot)
|
330
|
-
- Danielle Sucher (@DanielleSucher)
|
346
|
+
- Robby Grossman ([@freerobby](https://github.com/freerobby))
|
347
|
+
- Brendan Schwartz ([@bschwartz](https://github.com/bschwartz))
|
348
|
+
- Marshall Moutenot ([@mmoutenot](https://github.com/mmoutenot))
|
349
|
+
- Danielle Sucher ([@DanielleSucher](https://github.com/DanielleSucher))
|
350
|
+
- Anders Chen ([@chen-anders](https://github.com/chen-anders))
|
351
|
+
- Thomas O'Neil ([@alieander](https://github.com/alieander))
|
331
352
|
|
332
353
|
|
333
354
|
## MIT License
|
data/lib/nsq/client_base.rb
CHANGED
data/lib/nsq/connection.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'socket'
|
3
|
+
require 'openssl'
|
3
4
|
require 'timeout'
|
4
5
|
|
5
6
|
require_relative 'frames/error'
|
@@ -24,12 +25,14 @@ module Nsq
|
|
24
25
|
|
25
26
|
def initialize(opts = {})
|
26
27
|
@host = opts[:host] || (raise ArgumentError, 'host is required')
|
27
|
-
@port = opts[:port] || (raise ArgumentError, '
|
28
|
+
@port = opts[:port] || (raise ArgumentError, 'port is required')
|
28
29
|
@queue = opts[:queue]
|
29
30
|
@topic = opts[:topic]
|
30
31
|
@channel = opts[:channel]
|
31
32
|
@msg_timeout = opts[:msg_timeout] || 60_000 # 60s
|
32
33
|
@max_in_flight = opts[:max_in_flight] || 1
|
34
|
+
@ssl_context = opts[:ssl_context]
|
35
|
+
validate_ssl_context! if @ssl_context
|
33
36
|
|
34
37
|
if @msg_timeout < 1000
|
35
38
|
raise ArgumentError, 'msg_timeout cannot be less than 1000. it\'s in milliseconds.'
|
@@ -146,7 +149,7 @@ module Nsq
|
|
146
149
|
heartbeat_interval: 30_000, # 30 seconds
|
147
150
|
output_buffer: 16_000, # 16kb
|
148
151
|
output_buffer_timeout: 250, # 250ms
|
149
|
-
tls_v1:
|
152
|
+
tls_v1: !!@ssl_context,
|
150
153
|
snappy: false,
|
151
154
|
deflate: false,
|
152
155
|
sample_rate: 0, # disable sampling
|
@@ -314,6 +317,7 @@ module Nsq
|
|
314
317
|
# it gets to nsqd ahead of anything in the `@write_queue`
|
315
318
|
write_to_socket ' V2'
|
316
319
|
identify
|
320
|
+
upgrade_to_ssl_socket if @ssl_context
|
317
321
|
|
318
322
|
start_read_loop
|
319
323
|
start_write_loop
|
@@ -346,6 +350,23 @@ module Nsq
|
|
346
350
|
end
|
347
351
|
|
348
352
|
|
353
|
+
def upgrade_to_ssl_socket
|
354
|
+
@socket = OpenSSL::SSL::SSLSocket.new(@socket, openssl_context)
|
355
|
+
@socket.connect
|
356
|
+
end
|
357
|
+
|
358
|
+
|
359
|
+
def openssl_context
|
360
|
+
context = OpenSSL::SSL::SSLContext.new
|
361
|
+
context.cert = OpenSSL::X509::Certificate.new(File.open(@ssl_context[:certificate]))
|
362
|
+
context.key = OpenSSL::PKey::RSA.new(File.open(@ssl_context[:key]))
|
363
|
+
if @ssl_context[:ca_certificate]
|
364
|
+
context.ca_file = OpenSSL::X509::Certificate.new(File.open(@ssl_context[:ca_certificate])).to_pem
|
365
|
+
end
|
366
|
+
context
|
367
|
+
end
|
368
|
+
|
369
|
+
|
349
370
|
# Retry the supplied block with exponential backoff.
|
350
371
|
#
|
351
372
|
# Borrowed liberally from:
|
@@ -398,5 +419,18 @@ module Nsq
|
|
398
419
|
end
|
399
420
|
|
400
421
|
|
422
|
+
def validate_ssl_context!
|
423
|
+
[:key, :certificate].each do |key|
|
424
|
+
unless @ssl_context.has_key?(key)
|
425
|
+
raise ArgumentError.new "ssl_context requires a :#{key}"
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
[:key, :certificate, :ca_certificate].each do |key|
|
430
|
+
if @ssl_context[key] && !File.readable?(@ssl_context[key])
|
431
|
+
raise LoadError.new "ssl_context :#{key} is unreadable"
|
432
|
+
end
|
433
|
+
end
|
434
|
+
end
|
401
435
|
end
|
402
436
|
end
|
data/lib/nsq/consumer.rb
CHANGED
@@ -17,6 +17,7 @@ module Nsq
|
|
17
17
|
@max_in_flight = opts[:max_in_flight] || 1
|
18
18
|
@discovery_interval = opts[:discovery_interval] || 60
|
19
19
|
@msg_timeout = opts[:msg_timeout]
|
20
|
+
@ssl_context = opts[:ssl_context]
|
20
21
|
|
21
22
|
# This is where we queue up the messages we receive from each connection
|
22
23
|
@messages = opts[:queue] || Queue.new
|
data/lib/nsq/producer.rb
CHANGED
data/lib/version.rb
CHANGED
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.
|
4
|
+
version: 1.6.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-04-
|
11
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|