nsq-ruby 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -3
  3. data/lib/nsq/producer.rb +12 -3
  4. data/lib/version.rb +2 -2
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09966bb130fd77c7eb78c70c654afb4b2bd2246c
4
- data.tar.gz: a900ade8f7497c4fcc738cd82900f90da7bb0172
3
+ metadata.gz: d180f4522d2a62a998941655bc29879c6e894654
4
+ data.tar.gz: 7022613a3a9eeac5f11252d21b4e8dde1f605fda
5
5
  SHA512:
6
- metadata.gz: 9f7ce184b29b4eb00b46826a0ae3bbaa408cef197c89f6c074d4379c6e8e5623f38bcea1a587550c14734fdd19bb133f186ed910e85c5255c11d659ff70b4176
7
- data.tar.gz: 2a0360c7b8b90e9099ae1e3dc1ad96de0ead23b3732ccafdc02e851fcab4af9a087c44f43f96d1d5d5ab34c2da45c086616bc17e19cb1bf3b5a1bbf029cdcb10
6
+ metadata.gz: b33960a85c7bbe508b661ec87a415a27e3e276ac0a595a8fa2a82e4285fec62048060624991144a45794c2b9b8d09f3f1119740a9cc4b6b9ab75ccdf7b1a6f3e
7
+ data.tar.gz: 92c5a53bf14f5ab965b0973f70e2b7cf696e08e87e6b484349608420afb0c9b2abd40f2059168f2c63d8a5b35ee8ec6984663a176e9175012f250ccdd8057e19
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
 
@@ -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,15 @@ 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)
33
42
  # stringify the messages
34
43
  messages = raw_messages.map(&:to_s)
35
44
 
@@ -37,9 +46,9 @@ module Nsq
37
46
  connection = connection_for_write
38
47
 
39
48
  if messages.length > 1
40
- connection.mpub(@topic, messages)
49
+ connection.mpub(topic, messages)
41
50
  else
42
- connection.pub(@topic, messages.first)
51
+ connection.pub(topic, messages.first)
43
52
  end
44
53
  end
45
54
 
@@ -1,8 +1,8 @@
1
1
  module Nsq
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 2
5
- PATCH = 1
4
+ MINOR = 3
5
+ PATCH = 0
6
6
  BUILD = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
8
8
  end
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.2.1
4
+ version: 1.3.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-02-16 00:00:00.000000000 Z
11
+ date: 2015-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler