fastly_nsq 1.17.0 → 1.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.git-blame-ignore-revs +6 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -2
- data/ChangeLog.md +8 -1
- data/Gemfile +8 -8
- data/README.md +1 -1
- data/Rakefile +10 -11
- data/fastly_nsq.gemspec +26 -26
- data/lib/fastly_nsq/cli.rb +43 -50
- data/lib/fastly_nsq/consumer.rb +6 -6
- data/lib/fastly_nsq/feeder.rb +5 -7
- data/lib/fastly_nsq/http/nsqd.rb +28 -28
- data/lib/fastly_nsq/http/nsqlookupd.rb +11 -11
- data/lib/fastly_nsq/http.rb +4 -4
- data/lib/fastly_nsq/launcher.rb +16 -16
- data/lib/fastly_nsq/listener.rb +16 -16
- data/lib/fastly_nsq/manager.rb +13 -12
- data/lib/fastly_nsq/message.rb +4 -4
- data/lib/fastly_nsq/messenger.rb +7 -7
- data/lib/fastly_nsq/new_relic.rb +8 -8
- data/lib/fastly_nsq/priority_queue.rb +2 -2
- data/lib/fastly_nsq/priority_thread_pool.rb +3 -3
- data/lib/fastly_nsq/producer.rb +7 -7
- data/lib/fastly_nsq/safe_thread.rb +1 -1
- data/lib/fastly_nsq/testing.rb +4 -3
- data/lib/fastly_nsq/tls_options.rb +6 -6
- data/lib/fastly_nsq/version.rb +1 -1
- data/lib/fastly_nsq.rb +27 -29
- data/spec/cli_spec.rb +2 -2
- data/spec/consumer_spec.rb +12 -12
- data/spec/fastly_nsq_spec.rb +31 -31
- data/spec/feeder_spec.rb +4 -4
- data/spec/http/nsqd_spec.rb +23 -23
- data/spec/http/nsqlookupd_spec.rb +19 -19
- data/spec/http_spec.rb +22 -22
- data/spec/integration_spec.rb +10 -10
- data/spec/launcher_spec.rb +21 -21
- data/spec/listener_spec.rb +50 -50
- data/spec/manager_spec.rb +27 -27
- data/spec/matchers/delegate.rb +4 -4
- data/spec/message_spec.rb +19 -19
- data/spec/messenger_spec.rb +63 -64
- data/spec/new_relic.rb +27 -27
- data/spec/priority_thread_pool_spec.rb +2 -2
- data/spec/producer_spec.rb +30 -30
- data/spec/spec_helper.rb +12 -12
- data/spec/support/http.rb +2 -2
- data/spec/support/webmock.rb +1 -1
- data/spec/testing_spec.rb +12 -12
- data/spec/tls_options_spec.rb +47 -47
- metadata +7 -8
- data/.rubocop.yml +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6973f2a953a18f9f5b63d6e7225c94264f56485b4632a409c820b5b61f91b050
|
4
|
+
data.tar.gz: 1a8f39f1085191666a6ebccff53a8c6f691fad4770bea6a48affc8f7998a878b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da7997c5cdc6b8cb7d5feeacb0feab24c062076c92b8a3b23ddb49416d5a1fe57d0c241a68b20b5aed15c3a2c6cad89015557268dd2827fa49a7c63236de6300
|
7
|
+
data.tar.gz: 007a732d613f15d099e28f301db5537d35cfe7675d45f46946526eb275b5196496520a1b2f0aaf3c011414b0b55eafa19218f5f71cf6a9fb42ea59678fc11b1b
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.3
|
data/.travis.yml
CHANGED
@@ -2,13 +2,15 @@ language: ruby
|
|
2
2
|
cache: bundler
|
3
3
|
sudo: false
|
4
4
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.5
|
5
|
+
- 2.6.9
|
6
|
+
- 2.7.5
|
7
|
+
- 3.0.3
|
7
8
|
script:
|
8
9
|
- bundle exec rake
|
9
10
|
services:
|
10
11
|
- docker
|
11
12
|
before_install:
|
13
|
+
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
12
14
|
- docker-compose up -d
|
13
15
|
before_script:
|
14
16
|
- gem update --system
|
data/ChangeLog.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v1.17.1](https://github.com/fastly/fastly_nsq/tree/v1.17.1) (2022-02-23)
|
4
|
+
[Full Changelog](https://github.com/fastly/fastly_nsq/compare/v1.17.0...v1.17.1)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Use standardrb for style and formatting [\#104](https://github.com/fastly/fastly_nsq/pull/104)
|
9
|
+
|
3
10
|
## [v1.17.0](https://github.com/fastly/fastly_nsq/tree/v1.17.0) (2021-02-11)
|
4
11
|
[Full Changelog](https://github.com/fastly/fastly_nsq/compare/v1.16.0...v1.17.0)
|
5
12
|
|
@@ -447,4 +454,4 @@
|
|
447
454
|
## [v0.0.1](https://github.com/fastly/fastly_nsq/tree/v0.0.1) (2016-01-30)
|
448
455
|
|
449
456
|
|
450
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
457
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/Gemfile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem
|
10
|
-
gem
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
7
|
+
gem "bundler-audit"
|
8
|
+
gem "newrelic_rpm", require: false
|
9
|
+
gem "overcommit", "~> 0.32.0"
|
10
|
+
gem "rake"
|
11
|
+
gem "rdoc"
|
12
|
+
gem "standard"
|
13
|
+
gem "rubygems-tasks", "~> 0.2"
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# fastly_nsq [![Build Status](https://travis-ci.org/fastly/fastly_nsq.svg?branch=
|
1
|
+
# fastly_nsq [![Build Status](https://travis-ci.org/fastly/fastly_nsq.svg?branch=main)](https://travis-ci.org/fastly/fastly_nsq)
|
2
2
|
|
3
3
|
NSQ adapter and testing objects
|
4
4
|
for using the NSQ messaging system
|
data/Rakefile
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rubygems"
|
4
4
|
|
5
5
|
begin
|
6
|
-
require
|
6
|
+
require "bundler/setup"
|
7
7
|
rescue LoadError => e
|
8
8
|
abort e.message
|
9
9
|
end
|
10
10
|
|
11
|
-
require
|
11
|
+
require "rake"
|
12
12
|
|
13
|
-
require
|
13
|
+
require "rubygems/tasks"
|
14
14
|
Gem::Tasks.new
|
15
15
|
|
16
|
-
require
|
16
|
+
require "rdoc/task"
|
17
17
|
RDoc::Task.new
|
18
18
|
task doc: :rdoc
|
19
19
|
|
20
|
-
require
|
20
|
+
require "rspec/core/rake_task"
|
21
21
|
RSpec::Core::RakeTask.new(:spec)
|
22
22
|
|
23
|
-
require
|
23
|
+
require "bundler/audit/cli"
|
24
24
|
namespace :bundler do
|
25
|
-
desc
|
25
|
+
desc "Updates the ruby-advisory-db and runs audit"
|
26
26
|
task :audit do
|
27
27
|
%w[update check].each do |command|
|
28
28
|
Bundler::Audit::CLI.start [command]
|
@@ -30,8 +30,7 @@ namespace :bundler do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
require
|
34
|
-
RuboCop::RakeTask.new
|
33
|
+
require "standard/rake"
|
35
34
|
|
36
35
|
task(:default).clear
|
37
|
-
task default: [
|
36
|
+
task default: ["spec", "standard", "bundler:audit"]
|
data/fastly_nsq.gemspec
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "fastly_nsq/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |gem|
|
8
|
-
gem.name
|
9
|
-
gem.version
|
10
|
-
gem.summary
|
11
|
-
gem.description
|
12
|
-
gem.license
|
13
|
-
gem.authors
|
14
|
-
gem.email
|
15
|
-
gem.homepage
|
8
|
+
gem.name = "fastly_nsq"
|
9
|
+
gem.version = FastlyNsq::VERSION
|
10
|
+
gem.summary = "Fastly NSQ Adapter"
|
11
|
+
gem.description = "Helper classes for Fastly's NSQ Services"
|
12
|
+
gem.license = "MIT"
|
13
|
+
gem.authors = ["Tommy O'Neil", "Adarsh Pandit", "Joshua Wehner", "Lukas Eklund", "Josh Lane", "Hassan Shahid"]
|
14
|
+
gem.email = "tommy@fastly.com"
|
15
|
+
gem.homepage = "https://github.com/fastly/fastly_nsq"
|
16
16
|
|
17
|
-
gem.files
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
18
|
|
19
|
-
gem.executables
|
20
|
-
gem.test_files
|
21
|
-
gem.require_paths = [
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
22
|
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.add_development_dependency
|
25
|
-
gem.add_development_dependency
|
26
|
-
gem.add_development_dependency
|
27
|
-
gem.add_development_dependency
|
28
|
-
gem.add_development_dependency
|
29
|
-
gem.add_development_dependency
|
30
|
-
gem.add_development_dependency
|
31
|
-
gem.add_development_dependency
|
23
|
+
gem.add_development_dependency "awesome_print", "~> 1.6"
|
24
|
+
gem.add_development_dependency "bundler"
|
25
|
+
gem.add_development_dependency "dotenv"
|
26
|
+
gem.add_development_dependency "pry-byebug", "~> 3.3"
|
27
|
+
gem.add_development_dependency "rspec", "~> 3.4"
|
28
|
+
gem.add_development_dependency "rspec-eventually", "0.2"
|
29
|
+
gem.add_development_dependency "timecop"
|
30
|
+
gem.add_development_dependency "webmock", "~> 3.0"
|
31
|
+
gem.add_development_dependency "yard"
|
32
32
|
|
33
|
-
gem.add_dependency
|
34
|
-
gem.add_dependency
|
35
|
-
gem.add_dependency
|
33
|
+
gem.add_dependency "concurrent-ruby", "~> 1.0"
|
34
|
+
gem.add_dependency "nsq-ruby-fastly", "~> 2.4"
|
35
|
+
gem.add_dependency "priority_queue_cxx", "~> 0.3"
|
36
36
|
end
|
data/lib/fastly_nsq/cli.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/ClassLength
|
4
3
|
$stdout.sync = true
|
5
4
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
5
|
+
require "fastly_nsq"
|
6
|
+
require "fastly_nsq/launcher"
|
7
|
+
require "fastly_nsq/manager"
|
8
|
+
require "fileutils"
|
9
|
+
require "optparse"
|
10
|
+
require "singleton"
|
12
11
|
|
13
12
|
# Provides functionality to support running FastlyNsq as a command line
|
14
13
|
# application that listens and processes NSQ messages.
|
@@ -44,26 +43,24 @@ class FastlyNsq::CLI
|
|
44
43
|
|
45
44
|
read_loop
|
46
45
|
rescue Interrupt
|
47
|
-
FastlyNsq.logger.info
|
46
|
+
FastlyNsq.logger.info "Shutting down"
|
48
47
|
launcher.stop
|
49
48
|
# Explicitly exit so busy Processor threads can't block
|
50
49
|
# process shutdown.
|
51
|
-
FastlyNsq.logger.info
|
50
|
+
FastlyNsq.logger.info "Bye!"
|
52
51
|
exit(0)
|
53
52
|
end
|
54
53
|
|
55
54
|
private
|
56
55
|
|
57
56
|
def launcher
|
58
|
-
@launcher ||= FastlyNsq::Launcher.new(options)
|
57
|
+
@launcher ||= FastlyNsq::Launcher.new(**options)
|
59
58
|
end
|
60
59
|
|
61
60
|
def read_loop
|
62
61
|
trapped_read_io = trap_signals
|
63
|
-
|
64
|
-
|
65
|
-
break unless readable_io
|
66
|
-
signal = readable_io.first[0].gets.strip
|
62
|
+
while trapped_read_io.wait_readable
|
63
|
+
signal = trapped_read_io.gets.strip
|
67
64
|
handle_signal signal
|
68
65
|
end
|
69
66
|
end
|
@@ -72,51 +69,51 @@ class FastlyNsq::CLI
|
|
72
69
|
boot_rails
|
73
70
|
require options[:require] if options[:require]
|
74
71
|
FastlyNsq.logger.info "Running in #{RUBY_DESCRIPTION}"
|
75
|
-
FastlyNsq.logger.info
|
72
|
+
FastlyNsq.logger.info "Starting processing, hit Ctrl-C to stop" unless options[:daemon]
|
76
73
|
end
|
77
74
|
|
78
75
|
def boot_rails
|
79
|
-
return unless ENV[
|
76
|
+
return unless ENV["RAILS_ENV"]
|
80
77
|
|
81
|
-
require
|
82
|
-
require File.expand_path(
|
83
|
-
require File.expand_path(
|
78
|
+
require "rails"
|
79
|
+
require File.expand_path("./config/application.rb")
|
80
|
+
require File.expand_path("./config/environment.rb")
|
84
81
|
end
|
85
82
|
|
86
83
|
def parse(args)
|
87
84
|
opts = {}
|
88
85
|
|
89
86
|
@parser = OptionParser.new do |o|
|
90
|
-
o.on
|
87
|
+
o.on "-c", "--concurrency COUNT", "Number of threads used to process messages" do |arg|
|
91
88
|
opts[:max_threads] = arg
|
92
89
|
end
|
93
90
|
|
94
|
-
o.on
|
91
|
+
o.on "-d", "--daemon", "Daemonize process" do |arg|
|
95
92
|
opts[:daemonize] = arg
|
96
93
|
end
|
97
94
|
|
98
|
-
o.on
|
95
|
+
o.on "-L", "--logfile PATH", "path to writable logfile" do |arg|
|
99
96
|
opts[:logfile] = arg
|
100
97
|
end
|
101
98
|
|
102
|
-
o.on
|
99
|
+
o.on "-P", "--pidfile PATH", "path to pidfile" do |arg|
|
103
100
|
opts[:pidfile] = arg
|
104
101
|
end
|
105
102
|
|
106
|
-
o.on
|
103
|
+
o.on "-r", "--require [PATH|DIR]", "Location of message_processor definition" do |arg|
|
107
104
|
opts[:require] = arg
|
108
105
|
end
|
109
106
|
|
110
|
-
o.on
|
107
|
+
o.on "-v", "--verbose", "enable verbose logging output" do |arg|
|
111
108
|
opts[:verbose] = arg
|
112
109
|
end
|
113
110
|
|
114
|
-
o.on
|
111
|
+
o.on "-t", "--timeout SECONDS", "shutdown deadline timeout" do |arg|
|
115
112
|
opts[:timeout] = arg
|
116
113
|
end
|
117
114
|
end
|
118
115
|
|
119
|
-
@parser.banner =
|
116
|
+
@parser.banner = "fastly_nsq [options]"
|
120
117
|
@parser.parse!(args)
|
121
118
|
|
122
119
|
@options = opts
|
@@ -171,13 +168,11 @@ class FastlyNsq::CLI
|
|
171
168
|
sigs = %w[INT TERM TTIN USR1]
|
172
169
|
|
173
170
|
sigs.each do |sig|
|
174
|
-
|
175
|
-
|
176
|
-
self_write.puts(sig)
|
177
|
-
end
|
178
|
-
rescue ArgumentError
|
179
|
-
puts "Signal #{sig} not supported"
|
171
|
+
trap sig do
|
172
|
+
self_write.puts(sig)
|
180
173
|
end
|
174
|
+
rescue ArgumentError
|
175
|
+
puts "Signal #{sig} not supported"
|
181
176
|
end
|
182
177
|
self_read
|
183
178
|
end
|
@@ -185,28 +180,28 @@ class FastlyNsq::CLI
|
|
185
180
|
def handle_signal(sig)
|
186
181
|
FastlyNsq.logger.debug "Got #{sig} signal"
|
187
182
|
case sig
|
188
|
-
when
|
183
|
+
when "INT"
|
189
184
|
# Handle Ctrl-C in JRuby like MRI
|
190
185
|
# http://jira.codehaus.org/browse/JRUBY-4637
|
191
186
|
raise Interrupt
|
192
|
-
when
|
187
|
+
when "TERM"
|
193
188
|
# Heroku sends TERM and then waits 10 seconds for process to exit.
|
194
189
|
raise Interrupt
|
195
|
-
when
|
196
|
-
FastlyNsq.logger.info
|
190
|
+
when "USR1"
|
191
|
+
FastlyNsq.logger.info "Received USR1, no longer accepting new work"
|
197
192
|
launcher.stop_listeners
|
198
|
-
when
|
193
|
+
when "TTIN"
|
199
194
|
handle_ttin
|
200
195
|
end
|
201
196
|
end
|
202
197
|
|
203
198
|
def handle_ttin
|
204
199
|
Thread.list.each do |thread|
|
205
|
-
FastlyNsq.logger.warn "Thread TID-#{thread.object_id.to_s(36)} #{thread[
|
200
|
+
FastlyNsq.logger.warn "Thread TID-#{thread.object_id.to_s(36)} #{thread["fastly_nsq_label"]}"
|
206
201
|
if thread.backtrace
|
207
202
|
FastlyNsq.logger.warn thread.backtrace.join("\n")
|
208
203
|
else
|
209
|
-
FastlyNsq.logger.warn
|
204
|
+
FastlyNsq.logger.warn "<no backtrace available>"
|
210
205
|
end
|
211
206
|
end
|
212
207
|
end
|
@@ -224,26 +219,24 @@ class FastlyNsq::CLI
|
|
224
219
|
reopen(files_to_reopen)
|
225
220
|
|
226
221
|
[$stdout, $stderr].each do |io|
|
227
|
-
File.open(options.fetch(:logfile,
|
222
|
+
File.open(options.fetch(:logfile, "/dev/null"), "ab") do |f|
|
228
223
|
io.reopen(f)
|
229
224
|
end
|
230
225
|
io.sync = true
|
231
226
|
end
|
232
|
-
$stdin.reopen(
|
227
|
+
$stdin.reopen("/dev/null")
|
233
228
|
|
234
229
|
setup_logger
|
235
230
|
end
|
236
231
|
|
237
232
|
def reopen(files)
|
238
233
|
files.each do |file|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
FastlyNsq.logger.error "Non IOError reopening file: #{e.message}"
|
246
|
-
end
|
234
|
+
file.reopen file.path, "a+"
|
235
|
+
file.sync = true
|
236
|
+
rescue IOError => e
|
237
|
+
FastlyNsq.logger.warn "IOError reopening file: #{e.message}"
|
238
|
+
rescue => e
|
239
|
+
FastlyNsq.logger.error "Non IOError reopening file: #{e.message}"
|
247
240
|
end
|
248
241
|
end
|
249
242
|
|
data/lib/fastly_nsq/consumer.rb
CHANGED
@@ -78,11 +78,11 @@ class FastlyNsq::Consumer
|
|
78
78
|
# channel: 'channel'
|
79
79
|
# )
|
80
80
|
def initialize(topic:, channel:, queue: nil, tls_options: nil, connect_timeout: DEFAULT_CONNECTION_TIMEOUT, max_attempts: FastlyNsq.max_attempts, **options)
|
81
|
-
@topic
|
82
|
-
@channel
|
83
|
-
@tls_options
|
81
|
+
@topic = topic
|
82
|
+
@channel = channel
|
83
|
+
@tls_options = FastlyNsq::TlsOptions.as_hash(tls_options)
|
84
84
|
@connect_timeout = connect_timeout
|
85
|
-
@max_attempts
|
85
|
+
@max_attempts = max_attempts
|
86
86
|
|
87
87
|
@connection = connect(queue, **options)
|
88
88
|
end
|
@@ -106,8 +106,8 @@ class FastlyNsq::Consumer
|
|
106
106
|
channel: channel,
|
107
107
|
queue: queue,
|
108
108
|
max_attempts: max_attempts,
|
109
|
-
**options
|
110
|
-
}.merge(tls_options)
|
109
|
+
**options
|
110
|
+
}.merge(tls_options)
|
111
111
|
)
|
112
112
|
end
|
113
113
|
end
|
data/lib/fastly_nsq/feeder.rb
CHANGED
@@ -36,13 +36,11 @@ class FastlyNsq::Feeder
|
|
36
36
|
# @see Nsq::Connection#read_loop
|
37
37
|
def push(message)
|
38
38
|
FastlyNsq.manager.pool.post(priority) do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
raise ex
|
45
|
-
end
|
39
|
+
processor.call(message)
|
40
|
+
rescue => ex
|
41
|
+
FastlyNsq.logger.error ex
|
42
|
+
FastlyNsq.tracer.notice_error ex
|
43
|
+
raise ex
|
46
44
|
end
|
47
45
|
end
|
48
46
|
end
|
data/lib/fastly_nsq/http/nsqd.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "fastly_nsq/http"
|
4
4
|
|
5
5
|
class FastlyNsq::Http
|
6
6
|
##
|
@@ -13,11 +13,11 @@ class FastlyNsq::Http
|
|
13
13
|
def_delegator :client, :get
|
14
14
|
def_delegator :client, :post
|
15
15
|
|
16
|
-
BASE_NSQD_URL = ENV.fetch(
|
17
|
-
if ENV[
|
18
|
-
"https://#{ENV.fetch(
|
16
|
+
BASE_NSQD_URL = ENV.fetch("NSQD_URL") do
|
17
|
+
if ENV["NSQD_HTTPS_ADDRESS"]
|
18
|
+
"https://#{ENV.fetch("NSQD_HTTPS_ADDRESS")}"
|
19
19
|
else
|
20
|
-
"http://#{ENV.fetch(
|
20
|
+
"http://#{ENV.fetch("NSQD_HTTP_ADDRESS")}"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
VALID_FORMATS = %w[text json].freeze
|
@@ -27,13 +27,13 @@ class FastlyNsq::Http
|
|
27
27
|
#
|
28
28
|
# NOTE: The only "unhealthy" state is if nsqd failed to write messages to disk when overflow occurred.
|
29
29
|
def self.ping(**args)
|
30
|
-
new(request_uri:
|
30
|
+
new(request_uri: "/ping", **args).get
|
31
31
|
end
|
32
32
|
|
33
33
|
##
|
34
34
|
# NSQ version information
|
35
35
|
def self.info(**args)
|
36
|
-
new(request_uri:
|
36
|
+
new(request_uri: "/info", **args).get
|
37
37
|
end
|
38
38
|
|
39
39
|
##
|
@@ -47,12 +47,12 @@ class FastlyNsq::Http
|
|
47
47
|
#
|
48
48
|
# @example Fetch Statistics for topic: 'foo', channel: 'bar' as text
|
49
49
|
# Nsqd.stats(topic: 'foo', channel: 'bar', format: 'text')
|
50
|
-
def self.stats(topic: nil, channel: nil, format:
|
50
|
+
def self.stats(topic: nil, channel: nil, format: "json", **args)
|
51
51
|
raise InvalidFormatError unless VALID_FORMATS.include?(format)
|
52
|
-
params = {
|
52
|
+
params = {format: format}
|
53
53
|
params[:topic] = topic if topic
|
54
54
|
params[:channel] = channel if channel
|
55
|
-
new(request_uri:
|
55
|
+
new(request_uri: "/stats", **args).get(params)
|
56
56
|
end
|
57
57
|
|
58
58
|
##
|
@@ -62,9 +62,9 @@ class FastlyNsq::Http
|
|
62
62
|
# @param defer [String] the time in ms to delay message delivery
|
63
63
|
# @param message the message body
|
64
64
|
def self.pub(topic:, message:, defer: nil, **args)
|
65
|
-
params = {
|
65
|
+
params = {topic: topic}
|
66
66
|
params[:defer] = defer if defer
|
67
|
-
new(request_uri:
|
67
|
+
new(request_uri: "/pub", **args).post(params, message)
|
68
68
|
end
|
69
69
|
|
70
70
|
##
|
@@ -83,17 +83,17 @@ class FastlyNsq::Http
|
|
83
83
|
# @param topic [String] the topic to publish to
|
84
84
|
# @param binary [Boolean] enables binary mode
|
85
85
|
# @param message the messages to send with \n used to seperate messages
|
86
|
-
def self.mpub(topic:, binary: false,
|
87
|
-
binary_param = binary ?
|
88
|
-
raise NotImplementedError,
|
89
|
-
params = {
|
90
|
-
new(request_uri:
|
86
|
+
def self.mpub(topic:, message:, binary: false, **args)
|
87
|
+
binary_param = binary ? "true" : "false"
|
88
|
+
raise NotImplementedError, "binary mode has yet to be implemented" if binary
|
89
|
+
params = {topic: topic, binary: binary_param}
|
90
|
+
new(request_uri: "/mpub", **args).post(params, message)
|
91
91
|
end
|
92
92
|
|
93
93
|
##
|
94
94
|
# List of nsqlookupd TCP addresses
|
95
95
|
def self.config_nsqlookupd_tcp_addresses(**args)
|
96
|
-
new(request_uri:
|
96
|
+
new(request_uri: "/config/nsqlookupd_tcp_addresses", **args).get
|
97
97
|
end
|
98
98
|
|
99
99
|
##
|
@@ -101,7 +101,7 @@ class FastlyNsq::Http
|
|
101
101
|
#
|
102
102
|
# @param topic [String] the topic to create
|
103
103
|
def self.topic_create(topic:, **args)
|
104
|
-
new(request_uri:
|
104
|
+
new(request_uri: "/topic/create", **args).post(topic: topic)
|
105
105
|
end
|
106
106
|
|
107
107
|
##
|
@@ -109,7 +109,7 @@ class FastlyNsq::Http
|
|
109
109
|
#
|
110
110
|
# @param topic [String] the existing topic to delete
|
111
111
|
def self.topic_delete(topic:, **args)
|
112
|
-
new(request_uri:
|
112
|
+
new(request_uri: "/topic/delete", **args).post(topic: topic)
|
113
113
|
end
|
114
114
|
|
115
115
|
##
|
@@ -117,7 +117,7 @@ class FastlyNsq::Http
|
|
117
117
|
#
|
118
118
|
# @param topic [String] the existing topic to empty
|
119
119
|
def self.topic_empty(topic:, **args)
|
120
|
-
new(request_uri:
|
120
|
+
new(request_uri: "/topic/empty", **args).post(topic: topic)
|
121
121
|
end
|
122
122
|
|
123
123
|
##
|
@@ -126,7 +126,7 @@ class FastlyNsq::Http
|
|
126
126
|
#
|
127
127
|
# @param topic [String] the existing topic to pause
|
128
128
|
def self.topic_pause(topic:, **args)
|
129
|
-
new(request_uri:
|
129
|
+
new(request_uri: "/topic/pause", **args).post(topic: topic)
|
130
130
|
end
|
131
131
|
|
132
132
|
##
|
@@ -134,7 +134,7 @@ class FastlyNsq::Http
|
|
134
134
|
#
|
135
135
|
# @param topic [String] the existing, paused topic to unpause
|
136
136
|
def self.topic_unpause(topic:, **args)
|
137
|
-
new(request_uri:
|
137
|
+
new(request_uri: "/topic/unpause", **args).post(topic: topic)
|
138
138
|
end
|
139
139
|
|
140
140
|
##
|
@@ -143,7 +143,7 @@ class FastlyNsq::Http
|
|
143
143
|
# @param topic [String] the existing topic
|
144
144
|
# @param channel [String] the channel to create
|
145
145
|
def self.channel_create(topic:, channel:, **args)
|
146
|
-
new(request_uri:
|
146
|
+
new(request_uri: "/channel/create", **args).post(topic: topic, channel: channel)
|
147
147
|
end
|
148
148
|
|
149
149
|
##
|
@@ -152,7 +152,7 @@ class FastlyNsq::Http
|
|
152
152
|
# @param topic [String] the existing topic
|
153
153
|
# @param channel [String] the channel to delete
|
154
154
|
def self.channel_delete(topic:, channel:, **args)
|
155
|
-
new(request_uri:
|
155
|
+
new(request_uri: "/channel/delete", **args).post(topic: topic, channel: channel)
|
156
156
|
end
|
157
157
|
|
158
158
|
##
|
@@ -161,7 +161,7 @@ class FastlyNsq::Http
|
|
161
161
|
# @param topic [String] the existing topic
|
162
162
|
# @param channel [String] the channel to empty
|
163
163
|
def self.channel_empty(topic:, channel:, **args)
|
164
|
-
new(request_uri:
|
164
|
+
new(request_uri: "/channel/empty", **args).post(topic: topic, channel: channel)
|
165
165
|
end
|
166
166
|
|
167
167
|
##
|
@@ -171,7 +171,7 @@ class FastlyNsq::Http
|
|
171
171
|
# @param topic [String] the existing topic
|
172
172
|
# @param channel [String] the channel to pause
|
173
173
|
def self.channel_pause(topic:, channel:, **args)
|
174
|
-
new(request_uri:
|
174
|
+
new(request_uri: "/channel/pause", **args).post(topic: topic, channel: channel)
|
175
175
|
end
|
176
176
|
|
177
177
|
##
|
@@ -180,7 +180,7 @@ class FastlyNsq::Http
|
|
180
180
|
# @param topic [String] the existing topic
|
181
181
|
# @param channel [String] the existing, paused, channel to unpause
|
182
182
|
def self.channel_unpause(topic:, channel:, **args)
|
183
|
-
new(request_uri:
|
183
|
+
new(request_uri: "/channel/unpause", **args).post(topic: topic, channel: channel)
|
184
184
|
end
|
185
185
|
|
186
186
|
##
|