nsq-ruby 1.6.0 → 1.7.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: 74c7cac5f391e1845369f6589a19a411781bcd5a
4
- data.tar.gz: 87bff660b9a046e391cc5535eb05766c23d0ae41
3
+ metadata.gz: 7330baaeb160c2c5d5771c6694c67fd431b635b9
4
+ data.tar.gz: 69ab28adb8065ba95d8a6936fc6f437c8b28d1d7
5
5
  SHA512:
6
- metadata.gz: 287c61b256fd4473c43ead39228423044eb936a6823195388488c5e058ae6908833cef0fa62e659afa97ef4606f53501ad521cf9337dca3c56ced373f5eb851b
7
- data.tar.gz: 9eeb96b9dab4965e6b2df5910803117119e23b56b98ca3f5d871f7538ac487cac51cb17eb158f38aeaad62b87b35073936268beee9de2c8abcc80fff22e6804e
6
+ metadata.gz: ebb0f048f870b45ff0123406639b2cb824bd69e4db938efeaa1751fb60de78e2477864f55eab890ad919efc8cbe1da10a290d8d152f3c989b7697116c40cf04d
7
+ data.tar.gz: 5fd65ab036ffdef8d0460b839a358e93b19849668f007fe22f8d1ded73a781408faf32e4147f7c354c11cc113357e9e716e39d14070cc55c3ee7cb446e0f98bd
data/README.md CHANGED
@@ -25,6 +25,15 @@ producer.write('some-message')
25
25
  # Write a bunch of messages to NSQ (uses mpub)
26
26
  producer.write('one', 'two', 'three', 'four', 'five')
27
27
 
28
+ # Write a deferred message to NSQ (uses dpub)
29
+
30
+ # Message deferred of 10s
31
+ producer.deferred_write(10, 'one')
32
+
33
+ # Message deferred of 1250ms
34
+ producer.deferred_write(1.25, 'one')
35
+
36
+
28
37
  # Close the connection
29
38
  producer.terminate
30
39
  ```
@@ -341,7 +350,7 @@ Yes! It's used in several critical parts of our infrastructure at
341
350
  millions of messages a day.
342
351
 
343
352
 
344
- ## Authors
353
+ ## Authors & Contributors
345
354
 
346
355
  - Robby Grossman ([@freerobby](https://github.com/freerobby))
347
356
  - Brendan Schwartz ([@bschwartz](https://github.com/bschwartz))
@@ -349,6 +358,7 @@ millions of messages a day.
349
358
  - Danielle Sucher ([@DanielleSucher](https://github.com/DanielleSucher))
350
359
  - Anders Chen ([@chen-anders](https://github.com/chen-anders))
351
360
  - Thomas O'Neil ([@alieander](https://github.com/alieander))
361
+ - Unbekandt Léo ([@soulou](https://github.com/Soulou))
352
362
 
353
363
 
354
364
  ## MIT License
@@ -97,6 +97,9 @@ module Nsq
97
97
  write ["PUB #{topic}\n", message.bytesize, message].pack('a*l>a*')
98
98
  end
99
99
 
100
+ def dpub(topic, delay_in_ms, message)
101
+ write ["DPUB #{topic} #{delay_in_ms}\n", message.bytesize, message].pack('a*l>a*')
102
+ end
100
103
 
101
104
  def mpub(topic, messages)
102
105
  body = messages.map do |message|
data/lib/nsq/producer.rb CHANGED
@@ -29,7 +29,6 @@ module Nsq
29
29
  at_exit{terminate}
30
30
  end
31
31
 
32
-
33
32
  def write(*raw_messages)
34
33
  if !@topic
35
34
  raise 'No topic specified. Either specify a topic when instantiating the Producer or use write_to_topic.'
@@ -38,6 +37,17 @@ module Nsq
38
37
  write_to_topic(@topic, *raw_messages)
39
38
  end
40
39
 
40
+ # Arg 'delay' in seconds
41
+ def deferred_write(delay, *raw_messages)
42
+ if !@topic
43
+ raise 'No topic specified. Either specify a topic when instantiating the Producer or use write_to_topic.'
44
+ end
45
+ if delay < 0.0
46
+ raise "Delay can't be negative, use a positive float."
47
+ end
48
+
49
+ deferred_write_to_topic(@topic, delay, *raw_messages)
50
+ end
41
51
 
42
52
  def write_to_topic(topic, *raw_messages)
43
53
  # return error if message(s) not provided
@@ -56,6 +66,14 @@ module Nsq
56
66
  end
57
67
  end
58
68
 
69
+ def deferred_write_to_topic(topic, delay, *raw_messages)
70
+ raise ArgumentError, 'message not provided' if raw_messages.empty?
71
+ messages = raw_messages.map(&:to_s)
72
+ connection = connection_for_write
73
+ messages.each do |msg|
74
+ connection.dpub(topic, (delay * 1000).to_i, msg)
75
+ end
76
+ end
59
77
 
60
78
  private
61
79
  def connection_for_write
data/lib/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Nsq
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 6
4
+ MINOR = 7
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.6.0
4
+ version: 1.7.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-20 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler