nsq-ruby-maglev- 1.2.1.0 → 1.5.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 +47 -4
- data/lib/nsq/consumer.rb +13 -0
- data/lib/nsq/producer.rb +15 -3
- data/lib/version.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55fe876d7c1dbd2c80142f832d20bc8ecde1d0ae
|
4
|
+
data.tar.gz: 8dbd9c540ff8998c42b160def4f549bb2e72b8a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cad697caa38a0688ff28c091520e5e2bef9b41eeba667a1007031e55f9c7a15f631048f674eb4f13c75a6265b2da0ec547b3a234fb884fec2000dfbd5e4b0b8
|
7
|
+
data.tar.gz: 599313c8a267777d9d55368dbf744387023be73dbf7583f72015265ba02289f9771ed0642f65103088a62f22fd383080bd10543310ab8aa4e03ed1a29533bf8a
|
data/README.md
CHANGED
@@ -85,7 +85,7 @@ producer = Nsq::Producer.new(
|
|
85
85
|
|
86
86
|
### `#write`
|
87
87
|
|
88
|
-
Publishes one or more
|
88
|
+
Publishes one or more messages to nsqd. If you give it a single argument, it will
|
89
89
|
send it to nsqd via `PUB`. If you give it multiple arguments, it will send all
|
90
90
|
those messages to nsqd via `MPUB`. It will automatically call `to_s` on any
|
91
91
|
arguments you give it.
|
@@ -98,7 +98,7 @@ producer.write(123)
|
|
98
98
|
producer.write(456, 'another-message', { key: 'value' }.to_json)
|
99
99
|
```
|
100
100
|
|
101
|
-
If
|
101
|
+
If its connection to nsqd fails, it will automatically try to reconnect with
|
102
102
|
exponential backoff. Any messages that were sent to `#write` will be queued
|
103
103
|
and transmitted after reconnecting.
|
104
104
|
|
@@ -107,6 +107,22 @@ connection to nsqd fails, you can lose messages. This is acceptable for our use
|
|
107
107
|
cases, mostly because we are sending messages to a local nsqd instance and
|
108
108
|
failure is very rare.
|
109
109
|
|
110
|
+
|
111
|
+
### `#write_to_topic`
|
112
|
+
|
113
|
+
Publishes one or more messages to nsqd. Like `#write`, but allows you to specify
|
114
|
+
the topic. Use this method if you want a single producer instance to write to
|
115
|
+
multiple topics.
|
116
|
+
|
117
|
+
```Ruby
|
118
|
+
# Send a single message via PUB to the topic 'rutabega'
|
119
|
+
producer.write_to_topic('rutabega', 123)
|
120
|
+
|
121
|
+
# Send multiple messages via MPUB to the topic 'kohlrabi'
|
122
|
+
producer.write_to_topic('kohlrabi', 'a', 'b', 'c')
|
123
|
+
```
|
124
|
+
|
125
|
+
|
110
126
|
### `#connected?`
|
111
127
|
|
112
128
|
Returns true if it's currently connected to nsqd and false if not.
|
@@ -144,7 +160,7 @@ consumer = Nsq::Consumer.new(
|
|
144
160
|
nsqlookupd: ['127.0.0.1:4161', '4.5.6.7:4161'],
|
145
161
|
max_in_flight: 100,
|
146
162
|
discovery_interval: 30,
|
147
|
-
|
163
|
+
msg_timeout: 120_000
|
148
164
|
)
|
149
165
|
```
|
150
166
|
|
@@ -171,6 +187,32 @@ message = consumer.pop
|
|
171
187
|
If there are messages on the queue, `pop` will return one immediately. If there
|
172
188
|
are no messages on the queue, `pop` will block execution until one arrives.
|
173
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
|
+
|
174
216
|
|
175
217
|
### `#size`
|
176
218
|
|
@@ -285,11 +327,12 @@ millions of messages a day.
|
|
285
327
|
- Robby Grossman (@freerobby)
|
286
328
|
- Brendan Schwartz (@bschwartz)
|
287
329
|
- Marshall Moutenot (@mmoutenot)
|
330
|
+
- Danielle Sucher (@DanielleSucher)
|
288
331
|
|
289
332
|
|
290
333
|
## MIT License
|
291
334
|
|
292
|
-
Copyright (C)
|
335
|
+
Copyright (C) 2016 Wistia, Inc.
|
293
336
|
|
294
337
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
295
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/nsq/producer.rb
CHANGED
@@ -6,7 +6,7 @@ module Nsq
|
|
6
6
|
|
7
7
|
def initialize(opts = {})
|
8
8
|
@connections = {}
|
9
|
-
@topic = opts[:topic]
|
9
|
+
@topic = opts[:topic]
|
10
10
|
@discovery_interval = opts[:discovery_interval] || 60
|
11
11
|
|
12
12
|
nsqlookupds = []
|
@@ -30,6 +30,18 @@ module Nsq
|
|
30
30
|
|
31
31
|
|
32
32
|
def write(*raw_messages)
|
33
|
+
if !@topic
|
34
|
+
raise 'No topic specified. Either specify a topic when instantiating the Producer or use write_to_topic.'
|
35
|
+
end
|
36
|
+
|
37
|
+
write_to_topic(@topic, *raw_messages)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def write_to_topic(topic, *raw_messages)
|
42
|
+
# return error if message(s) not provided
|
43
|
+
raise ArgumentError, 'message not provided' if raw_messages.empty?
|
44
|
+
|
33
45
|
# stringify the messages
|
34
46
|
messages = raw_messages.map(&:to_s)
|
35
47
|
|
@@ -37,9 +49,9 @@ module Nsq
|
|
37
49
|
connection = connection_for_write
|
38
50
|
|
39
51
|
if messages.length > 1
|
40
|
-
connection.mpub(
|
52
|
+
connection.mpub(topic, messages)
|
41
53
|
else
|
42
|
-
connection.pub(
|
54
|
+
connection.pub(topic, messages.first)
|
43
55
|
end
|
44
56
|
end
|
45
57
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsq-ruby-maglev-
|
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:
|
11
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,5 +112,5 @@ rubyforge_project:
|
|
112
112
|
rubygems_version: 2.2.2
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
|
-
summary: Ruby client library for NSQ
|
115
|
+
summary: MagLev Ruby client library for NSQ
|
116
116
|
test_files: []
|