nsq-ruby 1.2.1 → 1.3.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 +19 -3
- data/lib/nsq/producer.rb +12 -3
- data/lib/version.rb +2 -2
- 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: d180f4522d2a62a998941655bc29879c6e894654
|
4
|
+
data.tar.gz: 7022613a3a9eeac5f11252d21b4e8dde1f605fda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
|
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,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(
|
49
|
+
connection.mpub(topic, messages)
|
41
50
|
else
|
42
|
-
connection.pub(
|
51
|
+
connection.pub(topic, messages.first)
|
43
52
|
end
|
44
53
|
end
|
45
54
|
|
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.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-
|
11
|
+
date: 2015-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|