nsq-ruby 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -1
- data/lib/nsq/consumer.rb +13 -0
- data/lib/version.rb +1 -1
- 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: 1cc303464874107233049891324ba89f7fdabeb9
|
4
|
+
data.tar.gz: f8f0d0d615f723893babdca18401221c0f86bbf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f797afecb530034108857cfee09ff0fb17d41d715d80cb1f10dfc527801de8ebc1cd707348908e743108a61ebddd942f1f964cadf4abb452d7a9f749572bb75d
|
7
|
+
data.tar.gz: b34ed2daeed5f863b6f81cf53d787fb4d11bbda45eaeabc01e5a75c33f9a7373ff72aadb4731ac7ca2b9df272ac15486dd97e59248acb7f8d0471937ba67ed89
|
data/README.md
CHANGED
@@ -187,6 +187,32 @@ message = consumer.pop
|
|
187
187
|
If there are messages on the queue, `pop` will return one immediately. If there
|
188
188
|
are no messages on the queue, `pop` will block execution until one arrives.
|
189
189
|
|
190
|
+
Be aware, while `#pop` is blocking, your process will be unresponsive. This
|
191
|
+
can be a problem in certain cases, like if you're trying to gracefully restart
|
192
|
+
a worker process by sending it a `TERM` signal. See `#pop_without_blocking` for
|
193
|
+
information on how to mitigate this issue.
|
194
|
+
|
195
|
+
|
196
|
+
### `#pop_without_blocking`
|
197
|
+
|
198
|
+
This is just like `#pop` except it doesn't block. It always returns immediately.
|
199
|
+
If there are no messages in the queue, it will return `nil`.
|
200
|
+
|
201
|
+
If you're consuming from a low-volume topic and don't want to get stuck in a
|
202
|
+
blocking state, you can use this method to consume messages like so:
|
203
|
+
|
204
|
+
```Ruby
|
205
|
+
loop do
|
206
|
+
if msg = @messages.pop_without_blocking
|
207
|
+
# do something
|
208
|
+
msg.finish
|
209
|
+
else
|
210
|
+
# wait for a bit before checking for new messages
|
211
|
+
sleep 0.01
|
212
|
+
end
|
213
|
+
end
|
214
|
+
```
|
215
|
+
|
190
216
|
|
191
217
|
### `#size`
|
192
218
|
|
@@ -301,11 +327,12 @@ millions of messages a day.
|
|
301
327
|
- Robby Grossman (@freerobby)
|
302
328
|
- Brendan Schwartz (@bschwartz)
|
303
329
|
- Marshall Moutenot (@mmoutenot)
|
330
|
+
- Danielle Sucher (@DanielleSucher)
|
304
331
|
|
305
332
|
|
306
333
|
## MIT License
|
307
334
|
|
308
|
-
Copyright (C)
|
335
|
+
Copyright (C) 2016 Wistia, Inc.
|
309
336
|
|
310
337
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
311
338
|
this software and associated documentation files (the "Software"), to deal in
|
data/lib/nsq/consumer.rb
CHANGED
@@ -48,6 +48,19 @@ module Nsq
|
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
|
+
# By default, if the internal queue is empty, pop will block until
|
52
|
+
# a new message comes in.
|
53
|
+
#
|
54
|
+
# Calling this method won't block. If there are no messages, it just
|
55
|
+
# returns nil.
|
56
|
+
def pop_without_blocking
|
57
|
+
@messages.pop(true)
|
58
|
+
rescue ThreadError
|
59
|
+
# When the Queue is empty calling `Queue#pop(true)` will raise a ThreadError
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
|
51
64
|
# returns the number of messages we have locally in the queue
|
52
65
|
def size
|
53
66
|
@messages.size
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wistia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|