fastly_nsq 1.17.1 → 1.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +2 -2
- data/.github/workflows/ruby.yml +30 -0
- data/.standard.yml +1 -0
- data/ChangeLog.md +7 -0
- data/README.md +80 -6
- data/fastly_nsq.gemspec +1 -2
- data/lib/fastly_nsq/consumer.rb +23 -10
- data/lib/fastly_nsq/producer.rb +20 -11
- data/lib/fastly_nsq/version.rb +1 -1
- data/lib/fastly_nsq.rb +38 -1
- data/spec/consumer_spec.rb +41 -0
- data/spec/fastly_nsq_spec.rb +80 -4
- data/spec/http/nsqd_spec.rb +2 -2
- data/spec/listener_spec.rb +3 -3
- data/spec/producer_spec.rb +45 -6
- metadata +8 -7
- data/.travis.yml +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 437c12c3efcf9025c66afa729cc9c3e9ae741712343d27b363cfa76168127f37
|
4
|
+
data.tar.gz: 9021787ce6740794c19f607eaefac99967457cf1b2920016fbc9a404009ed47b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 222ed5a9d8427dbb31ca9860feca33f31699483c2694c38be62cf1682e8cfaba09150228806af7fad11f20535315b798d00c95f7dd9e851c9897a3454a967861
|
7
|
+
data.tar.gz: 56c5e41343492893194f74fe61317d157bc4d27c7b53e2fc69180271d73da0de8cfca47bec5317b333bcfd1262b82b325184e0458f791df3966e9d53aef4c417
|
data/.env
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
permissions:
|
10
|
+
contents: read
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
ruby-version: ['2.7', '3.0', '3.1', '3.2']
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v3
|
22
|
+
- name: Start NSQ
|
23
|
+
run: docker-compose up -d
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby-version }}
|
28
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
29
|
+
- name: Run tests
|
30
|
+
run: bundle exec rake
|
data/.standard.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby_version: 2.7
|
data/ChangeLog.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v1.18.0](https://github.com/fastly/fastly_nsq/tree/v1.18.0) (2022-03-04)
|
4
|
+
[Full Changelog](https://github.com/fastly/fastly_nsq/compare/v1.17.1...v1.18.0)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Configurable NSQDs for Consumers and Producers [\#105](https://github.com/fastly/fastly_nsq/pull/105)
|
9
|
+
|
3
10
|
## [v1.17.1](https://github.com/fastly/fastly_nsq/tree/v1.17.1) (2022-02-23)
|
4
11
|
[Full Changelog](https://github.com/fastly/fastly_nsq/compare/v1.17.0...v1.17.1)
|
5
12
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# fastly_nsq [![Build Status](https://travis-ci.
|
1
|
+
# fastly_nsq [![Build Status](https://travis-ci.com/fastly/fastly_nsq.svg?branch=main)](https://travis-ci.com/fastly/fastly_nsq)
|
2
2
|
|
3
3
|
NSQ adapter and testing objects
|
4
4
|
for using the NSQ messaging system
|
@@ -12,9 +12,9 @@ We also include fakes
|
|
12
12
|
to make testing easier.
|
13
13
|
|
14
14
|
This library is dependent
|
15
|
-
on the [`nsq-ruby`] gem.
|
15
|
+
on the [`nsq-ruby-fastly`] gem.
|
16
16
|
|
17
|
-
[`nsq-ruby`]: https://github.com/
|
17
|
+
[`nsq-ruby-fastly`]: https://github.com/fastly/nsq-ruby
|
18
18
|
|
19
19
|
Please use [GitHub Issues] to report bugs.
|
20
20
|
|
@@ -34,6 +34,65 @@ and `bundle install`.
|
|
34
34
|
|
35
35
|
## Usage
|
36
36
|
|
37
|
+
### Connections
|
38
|
+
|
39
|
+
NSQD cconnections can be discovered via nsqlookupd's or
|
40
|
+
specified explicity for consumers and producers.
|
41
|
+
|
42
|
+
#### Using nsqlookup:
|
43
|
+
|
44
|
+
Set the ENV variable to a comma sepearated string of lookups:
|
45
|
+
|
46
|
+
```
|
47
|
+
ENV['NSQLOOKUPD_HTTP_ADDRESS'] = "lookup01:1234,lookup01:1234"
|
48
|
+
```
|
49
|
+
|
50
|
+
Or configure them directly:
|
51
|
+
|
52
|
+
```
|
53
|
+
FastlyNsq.configure do |config|
|
54
|
+
config.lookupd_http_addresses = ["lookup01:1234", "lookup02:1234"]
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
#### Using nsqd directly:
|
59
|
+
|
60
|
+
NSQD connections can be specified for consumers and producers. Being able to set
|
61
|
+
different sets for consumers and producers facilitates removing and adding new instances
|
62
|
+
without downtime.
|
63
|
+
|
64
|
+
Set the following ENV variables to a comma sepearted string of nsqds:
|
65
|
+
|
66
|
+
```
|
67
|
+
ENV['NSQD_CONSUMERS']="nsqd01:4150,nsd02:4150"
|
68
|
+
ENV['NSQD_PRODUCERS']="nsqd01:4150,nsd02:4150"
|
69
|
+
```
|
70
|
+
|
71
|
+
Or configure them directly:
|
72
|
+
|
73
|
+
```
|
74
|
+
FastlyNsq.configure do |config|
|
75
|
+
config.consumer_nsqds = ["nsqd01:4150", "nsqd02:4150"]
|
76
|
+
config.producer_nsqds = ["nsqd01:4150", "nsqd02:4150"]
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
### Connection Priority
|
81
|
+
|
82
|
+
When `FastlyNsq.consumer_nsqds` or `FastlyNsq.producer_nsqds` are set they
|
83
|
+
will be used instead of `FastlyNsq.lookupd_http_addresses`.
|
84
|
+
|
85
|
+
### TLS
|
86
|
+
|
87
|
+
Set the following ENV variables to enable TLS support:
|
88
|
+
|
89
|
+
```
|
90
|
+
NSQ_SSL_KEY
|
91
|
+
NSQ_SSL_CERTIFICATE
|
92
|
+
NSQ_SSL_CA_CERTIFICATE
|
93
|
+
NSQ_SSL_VERIFY_MODE (optional)
|
94
|
+
```
|
95
|
+
|
37
96
|
### `FastlyNsq::Producer`
|
38
97
|
|
39
98
|
This is a class
|
@@ -50,7 +109,6 @@ message_data = {
|
|
50
109
|
}
|
51
110
|
|
52
111
|
producer = FastlyNsq::Producer.new(
|
53
|
-
nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
|
54
112
|
topic: topic,
|
55
113
|
)
|
56
114
|
|
@@ -281,6 +339,22 @@ expect(some_result)
|
|
281
339
|
|
282
340
|
## Configuration
|
283
341
|
|
342
|
+
See the [documentation](https://www.rubydoc.info/gems/fastly_nsq/FastlyNsq) for additional settings
|
343
|
+
|
344
|
+
Example:
|
345
|
+
|
346
|
+
```
|
347
|
+
FastlyNsq.configure do |config|
|
348
|
+
config.channel = "z"
|
349
|
+
config.producer_nsqds = ["nsqd01:4150", "nsqd02:4150"]
|
350
|
+
config.lookupd_http_addresses = ["lookupd01:4161", "lookupd02:4161"]
|
351
|
+
config.logger = Logger.new(STDOUT)
|
352
|
+
config.max_attempts = 10
|
353
|
+
config.max_req_timeout = 10_000
|
354
|
+
config.max_processing_pool_threads = 42
|
355
|
+
end
|
356
|
+
```
|
357
|
+
|
284
358
|
### Environment Variables
|
285
359
|
|
286
360
|
The URLs for the various
|
@@ -293,10 +367,10 @@ stock NSQ on OS X,
|
|
293
367
|
installed via Homebrew:
|
294
368
|
|
295
369
|
```shell
|
296
|
-
NSQD_TCP_ADDRESS='127.0.0.1:4150'
|
297
370
|
NSQD_HTTP_ADDRESS='127.0.0.1:4151'
|
298
|
-
NSQLOOKUPD_TCP_ADDRESS='127.0.0.1:4160'
|
299
371
|
NSQLOOKUPD_HTTP_ADDRESS='127.0.0.1:4161, 10.1.1.101:4161'
|
372
|
+
NSQD_CONSUMERS='127.0.0.1:4150'
|
373
|
+
NSQD_PRODUCERS='127.0.0.1:4150'
|
300
374
|
```
|
301
375
|
|
302
376
|
See the [`.sample.env`](examples/.sample.env) file
|
data/fastly_nsq.gemspec
CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.files = `git ls-files`.split("\n")
|
18
18
|
|
19
19
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
20
|
-
gem.test_files = gem.files.grep(%r{^(test|features)/})
|
21
20
|
gem.require_paths = ["lib"]
|
22
21
|
|
23
22
|
gem.add_development_dependency "awesome_print", "~> 1.6"
|
@@ -31,6 +30,6 @@ Gem::Specification.new do |gem|
|
|
31
30
|
gem.add_development_dependency "yard"
|
32
31
|
|
33
32
|
gem.add_dependency "concurrent-ruby", "~> 1.0"
|
34
|
-
gem.add_dependency "nsq-ruby
|
33
|
+
gem.add_dependency "nsq-ruby", "~> 2.4.1"
|
35
34
|
gem.add_dependency "priority_queue_cxx", "~> 0.3"
|
36
35
|
end
|
data/lib/fastly_nsq/consumer.rb
CHANGED
@@ -61,6 +61,9 @@ class FastlyNsq::Consumer
|
|
61
61
|
##
|
62
62
|
# Create a FastlyNsq::Consumer
|
63
63
|
#
|
64
|
+
# Will connect to NSQDs in this priority: 1. direct from FastlyNsq.consumer_nsqds 2. discovered via FastlyNsq.lookupd_http_addresses.
|
65
|
+
# If both `consumer_nsqds` and `lookupd_http_addresses` are set only the FastlyNsq.consumer_nsqds will be used.
|
66
|
+
#
|
64
67
|
# @param topic [String] NSQ topic from which to consume
|
65
68
|
# @param channel [String] NSQ channel from which to consume
|
66
69
|
# @param queue [#pop, #size] Queue object, most likely an instance of {FastlyNsq::Feeder}
|
@@ -99,15 +102,25 @@ class FastlyNsq::Consumer
|
|
99
102
|
attr_reader :tls_options
|
100
103
|
|
101
104
|
def connect(queue, **options)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
)
|
105
|
+
consumers = FastlyNsq.consumer_nsqds
|
106
|
+
lookupd = FastlyNsq.lookupd_http_addresses
|
107
|
+
|
108
|
+
opts = {
|
109
|
+
topic: topic,
|
110
|
+
channel: channel,
|
111
|
+
queue: queue,
|
112
|
+
max_attempts: max_attempts,
|
113
|
+
**options
|
114
|
+
}.merge(tls_options)
|
115
|
+
|
116
|
+
if !consumers.empty?
|
117
|
+
opts[:nsqd] = consumers
|
118
|
+
elsif !lookupd.empty?
|
119
|
+
opts[:nsqlookupd] = lookupd
|
120
|
+
else
|
121
|
+
raise FastlyNsq::ConnectionFailed, "One of FastlyNsq.consumer_nsqds or FastlyNsq.lookupd_http_addresses must be present"
|
122
|
+
end
|
123
|
+
|
124
|
+
Nsq::Consumer.new(opts)
|
112
125
|
end
|
113
126
|
end
|
data/lib/fastly_nsq/producer.rb
CHANGED
@@ -24,6 +24,9 @@ class FastlyNsq::Producer
|
|
24
24
|
##
|
25
25
|
# Create a FastlyNsq::Producer
|
26
26
|
#
|
27
|
+
# Will connect to NSQDs in this priority: 1. direct from FastlyNsq.producer_nsqds 2. discovered via FastlyNsq.lookupd_http_addresses.
|
28
|
+
# If both `producer_nsqds` and `lookupd_http_addresses` are set only the FastlyNsq.producer_nsqds will be used.
|
29
|
+
#
|
27
30
|
# @param topic [String] NSQ topic on which to deliver the message
|
28
31
|
# @param tls_options [Hash] Hash of TSL options passed the connection.
|
29
32
|
# In most cases this should be nil unless you need to override the
|
@@ -71,27 +74,33 @@ class FastlyNsq::Producer
|
|
71
74
|
# Create an Nsq::Producer and set as +@connection+ instance variable
|
72
75
|
# @return [Boolean]
|
73
76
|
def connect
|
77
|
+
producers = FastlyNsq.producer_nsqds
|
74
78
|
lookupd = FastlyNsq.lookupd_http_addresses
|
75
79
|
|
76
|
-
|
77
|
-
tls_options.merge(
|
78
|
-
nsqlookupd: lookupd,
|
79
|
-
topic: topic
|
80
|
-
)
|
81
|
-
)
|
82
|
-
|
83
|
-
timeout_args = [connect_timeout, FastlyNsq::ConnectionFailed]
|
80
|
+
opts = tls_options.merge(topic: topic)
|
84
81
|
|
85
|
-
if
|
86
|
-
|
82
|
+
if !producers.empty?
|
83
|
+
opts[:nsqd] = producers
|
84
|
+
elsif !lookupd.empty?
|
85
|
+
opts[:nsqlookupd] = lookupd
|
86
|
+
else
|
87
|
+
raise FastlyNsq::ConnectionFailed, "One of FastlyNsq.producer_nsqds or FastlyNsq.lookupd_http_addresses must be present"
|
87
88
|
end
|
88
89
|
|
90
|
+
@connection ||= Nsq::Producer.new(opts)
|
91
|
+
|
92
|
+
timeout_args = [
|
93
|
+
connect_timeout,
|
94
|
+
FastlyNsq::ConnectionFailed,
|
95
|
+
"Failed connection to #{opts[:nsqd] || opts[:nsqlookupd]} within #{connect_timeout} seconds"
|
96
|
+
]
|
97
|
+
|
89
98
|
Timeout.timeout(*timeout_args) { Thread.pass until connection.connected? }
|
90
99
|
|
91
100
|
true
|
92
101
|
rescue FastlyNsq::ConnectionFailed
|
93
102
|
logger.error { "Producer for #{topic} failed to connect!" }
|
94
|
-
terminate
|
103
|
+
terminate if @connection
|
95
104
|
raise
|
96
105
|
end
|
97
106
|
|
data/lib/fastly_nsq/version.rb
CHANGED
data/lib/fastly_nsq.rb
CHANGED
@@ -126,7 +126,44 @@ module FastlyNsq
|
|
126
126
|
# Return an array of NSQ lookupd http addresses sourced from ENV['NSQLOOKUPD_HTTP_ADDRESS']
|
127
127
|
# @return [Array<String>] list of nsqlookupd http addresses
|
128
128
|
def lookupd_http_addresses
|
129
|
-
ENV.fetch("NSQLOOKUPD_HTTP_ADDRESS").split(
|
129
|
+
@lookups ||= ENV.fetch("NSQLOOKUPD_HTTP_ADDRESS", "").split(/, ?|\s+/).map(&:strip)
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# Set the lookupd_http_addresses
|
134
|
+
# @param lookups [Array] List of http lookupd addresses to use.
|
135
|
+
def lookupd_http_addresses=(lookups)
|
136
|
+
@lookups = lookups.nil? ? nil : Array(lookups)
|
137
|
+
end
|
138
|
+
|
139
|
+
##
|
140
|
+
# Return an array of NSQD TCP addresses for NSQ consumers. Defaults to the value of ENV['NSQD_CONSUMERS'].
|
141
|
+
# ENV['NSQD_CONSUMERS'] must be a comma or space seperated string of NSQD addresses
|
142
|
+
# @return [Array<String>] list of nsqd addresses
|
143
|
+
def consumer_nsqds
|
144
|
+
@consumer_nsqds ||= ENV.fetch("NSQD_CONSUMERS", "").split(/, ?|\s+/).map(&:strip)
|
145
|
+
end
|
146
|
+
|
147
|
+
##
|
148
|
+
# Set the consumer_nsqd addresses
|
149
|
+
# @param nsqd_addresses [Array] List of consumer nsqd addresses to use
|
150
|
+
def consumer_nsqds=(nsqd_addresses)
|
151
|
+
@consumer_nsqds = nsqd_addresses.nil? ? nil : Array(nsqd_addresses)
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
# Return an array of NSQD TCP addresses for NSQ producers. Defaults to the value of ENV['NSQD_PRODUCERS'].
|
156
|
+
# ENV['NSQD_PRODUCERS'] must be a comma or space seperated string of NSQD addresses
|
157
|
+
# @return [Array<String>] list of nsqd addresses
|
158
|
+
def producer_nsqds
|
159
|
+
@producer_nsqds ||= ENV.fetch("NSQD_PRODUCERS", "").split(/, ?|\s+/).map(&:strip)
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# Set the producer_nsqd addresses
|
164
|
+
# @param nsqd_addresses [Array] List of producer nsqd addresses to use
|
165
|
+
def producer_nsqds=(nsqd_addresses)
|
166
|
+
@producer_nsqds = nsqd_addresses.nil? ? nil : Array(nsqd_addresses)
|
130
167
|
end
|
131
168
|
|
132
169
|
# Register a block to run at a point in the lifecycle.
|
data/spec/consumer_spec.rb
CHANGED
@@ -56,4 +56,45 @@ RSpec.describe FastlyNsq::Consumer do
|
|
56
56
|
it { should be_empty }
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
describe "connection priority" do
|
61
|
+
after do
|
62
|
+
FastlyNsq.lookupd_http_addresses = nil
|
63
|
+
FastlyNsq.consumer_nsqds = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it "connects to consumer_nsqds if provided" do
|
67
|
+
allow(Nsq::Consumer).to receive(:new)
|
68
|
+
|
69
|
+
expect(FastlyNsq.lookupd_http_addresses).not_to be_empty
|
70
|
+
expect(FastlyNsq.consumer_nsqds).not_to be_empty
|
71
|
+
|
72
|
+
FastlyNsq::Consumer.new(topic: topic, channel: channel)
|
73
|
+
expect(Nsq::Consumer).to have_received(:new).with a_hash_including(nsqd: FastlyNsq.consumer_nsqds).and(excluding(:nsqlookupd))
|
74
|
+
end
|
75
|
+
|
76
|
+
it "connects to lookupd_http_addresses if consumer_nsqds is empty" do
|
77
|
+
FastlyNsq.consumer_nsqds = []
|
78
|
+
allow(Nsq::Consumer).to receive(:new)
|
79
|
+
|
80
|
+
expect(FastlyNsq.lookupd_http_addresses).not_to be_empty
|
81
|
+
expect(FastlyNsq.consumer_nsqds).to be_empty
|
82
|
+
|
83
|
+
FastlyNsq::Consumer.new(topic: topic, channel: channel)
|
84
|
+
expect(Nsq::Consumer).to have_received(:new).with a_hash_including(nsqlookupd: FastlyNsq.lookupd_http_addresses).and(excluding(:nsqd))
|
85
|
+
end
|
86
|
+
|
87
|
+
it "raises when neither consumer_nsqds or lookupd_http_addresses are available" do
|
88
|
+
FastlyNsq.consumer_nsqds = []
|
89
|
+
FastlyNsq.lookupd_http_addresses = []
|
90
|
+
allow(Nsq::Consumer).to receive(:new)
|
91
|
+
|
92
|
+
expect(FastlyNsq.lookupd_http_addresses).to be_empty
|
93
|
+
expect(FastlyNsq.consumer_nsqds).to be_empty
|
94
|
+
|
95
|
+
expect { FastlyNsq::Consumer.new(topic: topic, channel: channel) }
|
96
|
+
.to raise_error(FastlyNsq::ConnectionFailed, "One of FastlyNsq.consumer_nsqds or FastlyNsq.lookupd_http_addresses must be present")
|
97
|
+
expect(Nsq::Consumer).not_to have_received(:new)
|
98
|
+
end
|
99
|
+
end
|
59
100
|
end
|
data/spec/fastly_nsq_spec.rb
CHANGED
@@ -37,7 +37,10 @@ RSpec.describe FastlyNsq do
|
|
37
37
|
|
38
38
|
describe "#logger" do
|
39
39
|
let!(:default_logger) { subject.logger }
|
40
|
-
after
|
40
|
+
after do
|
41
|
+
subject.logger = default_logger
|
42
|
+
$stderr = STDERR
|
43
|
+
end
|
41
44
|
|
42
45
|
it "returns the set logger" do
|
43
46
|
logger = Logger.new(nil)
|
@@ -47,6 +50,7 @@ RSpec.describe FastlyNsq do
|
|
47
50
|
end
|
48
51
|
|
49
52
|
it "sets the default logger if none is set" do
|
53
|
+
$stderr = File.new("/dev/null", "w")
|
50
54
|
subject.instance_variable_set(:@logger, nil)
|
51
55
|
expect(subject.instance_variable_get(:@logger)).to be nil
|
52
56
|
logger = subject.logger
|
@@ -62,14 +66,14 @@ RSpec.describe FastlyNsq do
|
|
62
66
|
after { subject.logger = default_logger }
|
63
67
|
|
64
68
|
it "allows the logger to be set and retrieved" do
|
65
|
-
logger = Logger.new(
|
69
|
+
logger = Logger.new("/dev/null")
|
66
70
|
subject.logger = logger
|
67
71
|
|
68
72
|
expect(subject.logger).to eq logger
|
69
73
|
end
|
70
74
|
|
71
75
|
it "sets Nsq.logger" do
|
72
|
-
logger = Logger.new(
|
76
|
+
logger = Logger.new("/dev/null")
|
73
77
|
subject.logger = logger
|
74
78
|
|
75
79
|
expect(Nsq.logger).to eq logger
|
@@ -94,9 +98,81 @@ RSpec.describe FastlyNsq do
|
|
94
98
|
end
|
95
99
|
|
96
100
|
describe "#lookupd_http_addresses" do
|
97
|
-
|
101
|
+
after { subject.instance_variable_set(:@lookups, nil) }
|
102
|
+
|
103
|
+
it "retreives NSQLOOKUPD_HTTP_ADDRESS by default" do
|
98
104
|
expect(subject.lookupd_http_addresses).to eq(ENV["NSQLOOKUPD_HTTP_ADDRESS"].split(","))
|
99
105
|
end
|
106
|
+
|
107
|
+
it "returns the value of the instance variable" do
|
108
|
+
subject.instance_variable_set(:@lookups, ["lolcathost"])
|
109
|
+
|
110
|
+
expect(subject.lookupd_http_addresses).to eq(["lolcathost"])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#lookupd_http_addresses=" do
|
115
|
+
let!(:default_loookups) { subject.lookupd_http_addresses }
|
116
|
+
after { subject.lookupd_http_addresses = default_loookups }
|
117
|
+
|
118
|
+
it "allows the lookups to be set and retrieved" do
|
119
|
+
lookups = ["lolcathost:1234"]
|
120
|
+
subject.lookupd_http_addresses = lookups
|
121
|
+
|
122
|
+
expect(subject.lookupd_http_addresses).to eq lookups
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#producer_nsqds" do
|
127
|
+
after { subject.instance_variable_set(:@producer_nsqds, nil) }
|
128
|
+
|
129
|
+
it "retreives NSQD_PRODUCERS by default" do
|
130
|
+
expect(subject.producer_nsqds).to eq(ENV["NSQD_PRODUCERS"].split(","))
|
131
|
+
end
|
132
|
+
|
133
|
+
it "returns the value of the instance variable" do
|
134
|
+
subject.instance_variable_set(:@producer_nsqds, ["producer:1234"])
|
135
|
+
|
136
|
+
expect(subject.producer_nsqds).to eq(["producer:1234"])
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#producer_nsqds=" do
|
141
|
+
let!(:default_producers) { subject.producer_nsqds }
|
142
|
+
after { subject.producer_nsqds = default_producers }
|
143
|
+
|
144
|
+
it "allows the producer_nsqds to be set and retrieved" do
|
145
|
+
producers = ["producer:1234"]
|
146
|
+
subject.producer_nsqds = producers
|
147
|
+
|
148
|
+
expect(subject.producer_nsqds).to eq producers
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#consumer_nsqds" do
|
153
|
+
after { subject.instance_variable_set(:@consumer_nsqds, nil) }
|
154
|
+
|
155
|
+
it "retreives NSQD_CONSUMERS by default" do
|
156
|
+
expect(subject.consumer_nsqds).to eq(ENV["NSQD_CONSUMERS"].split(","))
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns the value of the instance variable" do
|
160
|
+
subject.instance_variable_set(:@consumer_nsqds, ["consumer:1234"])
|
161
|
+
|
162
|
+
expect(subject.consumer_nsqds).to eq(["consumer:1234"])
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "#consumer_nsqds=" do
|
167
|
+
let!(:default_consumers) { subject.consumer_nsqds }
|
168
|
+
after { subject.consumer_nsqds = default_consumers }
|
169
|
+
|
170
|
+
it "allows the consumer_nsqds to be set and retrieved" do
|
171
|
+
consumers = ["consumer:1234"]
|
172
|
+
subject.consumer_nsqds = consumers
|
173
|
+
|
174
|
+
expect(subject.consumer_nsqds).to eq consumers
|
175
|
+
end
|
100
176
|
end
|
101
177
|
|
102
178
|
describe "#on" do
|
data/spec/http/nsqd_spec.rb
CHANGED
@@ -63,7 +63,7 @@ RSpec.describe FastlyNsq::Http::Nsqd, :webmock do
|
|
63
63
|
stub_request(:post, url)
|
64
64
|
data = {topic: "lol"}
|
65
65
|
|
66
|
-
FastlyNsq::Http::Nsqd.send("topic_#{verb}"
|
66
|
+
FastlyNsq::Http::Nsqd.send(:"topic_#{verb}", topic: "lol", base_uri: base_uri)
|
67
67
|
|
68
68
|
expect(a_request(:post, url).with(query: data)).to have_been_requested
|
69
69
|
|
@@ -71,7 +71,7 @@ RSpec.describe FastlyNsq::Http::Nsqd, :webmock do
|
|
71
71
|
stub_request(:post, url)
|
72
72
|
data = {topic: "lol", channel: "foo"}
|
73
73
|
|
74
|
-
FastlyNsq::Http::Nsqd.send("channel_#{verb}"
|
74
|
+
FastlyNsq::Http::Nsqd.send(:"channel_#{verb}", topic: "lol", channel: "foo", base_uri: base_uri)
|
75
75
|
|
76
76
|
expect(a_request(:post, url).with(query: data)).to have_been_requested
|
77
77
|
end
|
data/spec/listener_spec.rb
CHANGED
@@ -96,7 +96,7 @@ RSpec.describe FastlyNsq::Listener do
|
|
96
96
|
describe "#call" do
|
97
97
|
it "processes a message" do
|
98
98
|
body = {"foo" => "bar"}
|
99
|
-
message = spy("message", body: JSON.dump(body))
|
99
|
+
message = spy("message", body: JSON.dump(body), attempts: 1, id: 1)
|
100
100
|
expect { subject.call(message) }.to change { messages }.to([body])
|
101
101
|
end
|
102
102
|
|
@@ -104,7 +104,7 @@ RSpec.describe FastlyNsq::Listener do
|
|
104
104
|
let(:processor) { ->(_) { true } }
|
105
105
|
|
106
106
|
it "finishes the message" do
|
107
|
-
message = spy("message", body: "{}")
|
107
|
+
message = spy("message", body: "{}", attempts: 1, id: 1)
|
108
108
|
subject.call(message)
|
109
109
|
|
110
110
|
expect(message).to have_received(:finish)
|
@@ -115,7 +115,7 @@ RSpec.describe FastlyNsq::Listener do
|
|
115
115
|
let(:processor) { ->(_) { false } }
|
116
116
|
|
117
117
|
it "finishes the message" do
|
118
|
-
message = spy("message", body: "{}")
|
118
|
+
message = spy("message", body: "{}", attempts: 1, id: 1)
|
119
119
|
subject.call(message)
|
120
120
|
|
121
121
|
expect(message).not_to have_received(:finish)
|
data/spec/producer_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
|
+
RSpec::Matchers.define_negated_matcher :excluding, :include
|
4
5
|
|
5
6
|
RSpec.describe FastlyNsq::Producer do
|
6
7
|
let!(:topic) { "fnsq" }
|
@@ -42,12 +43,50 @@ RSpec.describe FastlyNsq::Producer do
|
|
42
43
|
logger = spy("logger")
|
43
44
|
expect(logger).to receive(:error).and_return("Producer for #{topic} failed to connect!")
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
expect { FastlyNsq::Producer.new(topic: topic, logger: logger, connect_timeout: 0.2) }
|
47
|
+
.to raise_error(FastlyNsq::ConnectionFailed, match(FastlyNsq.lookupd_http_addresses.inspect))
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "connection priority" do
|
51
|
+
after do
|
52
|
+
FastlyNsq.lookupd_http_addresses = nil
|
53
|
+
FastlyNsq.producer_nsqds = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "connects to producer_nsqds if provided" do
|
57
|
+
connection = double "FastlyNsq::Producer", connected?: true
|
58
|
+
allow(Nsq::Producer).to receive(:new).and_return(connection)
|
59
|
+
|
60
|
+
expect(FastlyNsq.lookupd_http_addresses).not_to be_empty
|
61
|
+
expect(FastlyNsq.producer_nsqds).not_to be_empty
|
62
|
+
|
63
|
+
FastlyNsq::Producer.new(topic: topic)
|
64
|
+
expect(Nsq::Producer).to have_received(:new).with a_hash_including(nsqd: FastlyNsq.producer_nsqds).and(excluding(:nsqlookupd))
|
65
|
+
end
|
66
|
+
|
67
|
+
it "connects to lookupd_http_addresses if producer_nsqds is empty" do
|
68
|
+
FastlyNsq.producer_nsqds = []
|
69
|
+
connection = double "FastlyNsq::Producer", connected?: true
|
70
|
+
allow(Nsq::Producer).to receive(:new).and_return(connection)
|
71
|
+
|
72
|
+
expect(FastlyNsq.lookupd_http_addresses).not_to be_empty
|
73
|
+
expect(FastlyNsq.producer_nsqds).to be_empty
|
74
|
+
|
75
|
+
FastlyNsq::Producer.new(topic: topic)
|
76
|
+
expect(Nsq::Producer).to have_received(:new).with a_hash_including(nsqlookupd: FastlyNsq.lookupd_http_addresses).and(excluding(:nsqd))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "raises when neither producer_nsqds or lookupd_http_addresses are available" do
|
80
|
+
FastlyNsq.producer_nsqds = []
|
81
|
+
FastlyNsq.lookupd_http_addresses = []
|
82
|
+
allow(Nsq::Producer).to receive(:new)
|
83
|
+
|
84
|
+
expect(FastlyNsq.lookupd_http_addresses).to be_empty
|
85
|
+
expect(FastlyNsq.producer_nsqds).to be_empty
|
86
|
+
|
87
|
+
expect { FastlyNsq::Producer.new(topic: topic) }
|
88
|
+
.to raise_error(FastlyNsq::ConnectionFailed, "One of FastlyNsq.producer_nsqds or FastlyNsq.lookupd_http_addresses must be present")
|
89
|
+
expect(Nsq::Producer).not_to have_received(:new)
|
51
90
|
end
|
52
91
|
end
|
53
92
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastly_nsq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.18.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommy O'Neil
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date:
|
16
|
+
date: 2024-01-18 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: awesome_print
|
@@ -156,19 +156,19 @@ dependencies:
|
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '1.0'
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
|
-
name: nsq-ruby
|
159
|
+
name: nsq-ruby
|
160
160
|
requirement: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
162
|
- - "~>"
|
163
163
|
- !ruby/object:Gem::Version
|
164
|
-
version:
|
164
|
+
version: 2.4.1
|
165
165
|
type: :runtime
|
166
166
|
prerelease: false
|
167
167
|
version_requirements: !ruby/object:Gem::Requirement
|
168
168
|
requirements:
|
169
169
|
- - "~>"
|
170
170
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
171
|
+
version: 2.4.1
|
172
172
|
- !ruby/object:Gem::Dependency
|
173
173
|
name: priority_queue_cxx
|
174
174
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,11 +194,12 @@ files:
|
|
194
194
|
- ".env"
|
195
195
|
- ".git-blame-ignore-revs"
|
196
196
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
197
|
+
- ".github/workflows/ruby.yml"
|
197
198
|
- ".gitignore"
|
198
199
|
- ".overcommit.yml"
|
199
200
|
- ".rdoc_options"
|
200
201
|
- ".ruby-version"
|
201
|
-
- ".
|
202
|
+
- ".standard.yml"
|
202
203
|
- ChangeLog.md
|
203
204
|
- Gemfile
|
204
205
|
- LICENSE.txt
|
@@ -269,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
270
|
- !ruby/object:Gem::Version
|
270
271
|
version: '0'
|
271
272
|
requirements: []
|
272
|
-
rubygems_version: 3.
|
273
|
+
rubygems_version: 3.3.7
|
273
274
|
signing_key:
|
274
275
|
specification_version: 4
|
275
276
|
summary: Fastly NSQ Adapter
|
data/.travis.yml
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
sudo: false
|
4
|
-
rvm:
|
5
|
-
- 2.6.9
|
6
|
-
- 2.7.5
|
7
|
-
- 3.0.3
|
8
|
-
script:
|
9
|
-
- bundle exec rake
|
10
|
-
services:
|
11
|
-
- docker
|
12
|
-
before_install:
|
13
|
-
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
14
|
-
- docker-compose up -d
|
15
|
-
before_script:
|
16
|
-
- gem update --system
|
17
|
-
notifications:
|
18
|
-
slack:
|
19
|
-
rooms:
|
20
|
-
secure: Uo78FoH8dwSbt7BjTcfb62RXW8aU5h2se+bs0fHSXNrzh6D3Zl+JmwzMkgN8u7M6F0WsOy6RhilYggRYAGds4K1CUi0wGJOG86NaXB4igqBIdHa6f6vzMQZoXxJk8ekc/0NFCj2UV+2Obt6FpeUZvF0Y+u029k5gN0SROfrN+ANtSq+jbI8sdsCCsedXHgDWnGsZS1hHleiRF1Q6VfKnBFcewPP/W49gzbABlKk2MjkVhse6kg+7+LRXfnDxh+aaRXBGYfzmGn4+gS6Jey63U0woAa8TdP/THlwhgvvBS0kwMMaCss+Uq1690lnVV5MX84Fsm4C+A9gbdJmlansLrYRRWm4aaAf8IGlqRTwx3F2yNHTaPA2zmkooFtn1kTuz1J8L9NjsVPPkATMAg3rTIhel+YkVK8q0Q9N9A70+P2u+Rp3htgjxVPMN7Ve9GqejUEaw690Wsp4hCK5tINj8Aq42ET/RpQt4Rzx78Vk4jEK+9UsFuuRH+awAJu/UsnA0JMTq9Smgk2kE69McVNfYPXRIRQXWAkV2dc6FwI8AAmqRusTeyWMK9SOQNXhlmry5ltWfAnHtuKdq9delbc1iOkcj8u9sCBkTz0ZogsI2oHpLlrw2oHFe49kSOkB5HMSQo8IOR7yXHAZ41lmd87/T367bak9HGqsCrweJL7Vz2Mw=
|
21
|
-
on_success: change
|
22
|
-
on_failure: change
|
23
|
-
email:
|
24
|
-
on_success: never
|
25
|
-
on_failure: never
|