nsq-ruby-maglev- 1.2.1.0 → 1.5.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: 404388ace1303e56c07f6b18284a81abe2cd03e8
4
- data.tar.gz: 77946db3d3f9d10a2d515ff75ac3ca48888fbc55
3
+ metadata.gz: 55fe876d7c1dbd2c80142f832d20bc8ecde1d0ae
4
+ data.tar.gz: 8dbd9c540ff8998c42b160def4f549bb2e72b8a3
5
5
  SHA512:
6
- metadata.gz: 106aa12520e1d473c57ff760eff08267c5bd1294a0586dc06ee607d513722a0e9651435eea6a2ef4403d72f70bfd50e412909e4bfc93740e58e756d89c490132
7
- data.tar.gz: 24d46489acd7a824001d0a6720e0b9bedc1b259e27a974fbe7e5c8b33b83259fc3555aea1ae1749785e31ac6def0d7eb543b3a9cd8e018055c73cbc9d816a98e
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 message to nsqd. If you give it a single argument, it will
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 it's connection to nsqd fails, it will automatically try to reconnect with
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
- msq_timeout: 120_000
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) 2014 Wistia, Inc.
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
@@ -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
@@ -6,7 +6,7 @@ module Nsq
6
6
 
7
7
  def initialize(opts = {})
8
8
  @connections = {}
9
- @topic = opts[:topic] || raise(ArgumentError, 'topic is required')
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(@topic, messages)
52
+ connection.mpub(topic, messages)
41
53
  else
42
- connection.pub(@topic, messages.first)
54
+ connection.pub(topic, messages.first)
43
55
  end
44
56
  end
45
57
 
@@ -1,9 +1,9 @@
1
1
  module Nsq
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 2
5
- PATCH = 1
6
- BUILD = 0
4
+ MINOR = 5
5
+ PATCH = 0
6
+ BUILD = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
8
8
  end
9
9
  end
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.2.1.0
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-08-14 00:00:00.000000000 Z
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: []