songkick_queue 0.3.0 → 0.4.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 +11 -8
- data/examples/environment.rb +1 -1
- data/examples/producer.rb +1 -1
- data/lib/songkick_queue.rb +16 -2
- data/lib/songkick_queue/client.rb +9 -8
- data/lib/songkick_queue/consumer.rb +0 -2
- data/lib/songkick_queue/producer.rb +2 -4
- data/lib/songkick_queue/version.rb +1 -1
- data/songkick_queue.gemspec +1 -1
- data/spec/songkick_queue/consumer_spec.rb +0 -12
- data/spec/songkick_queue/producer_spec.rb +0 -23
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75d2f489f41e935f1c16ef27861a7d9044472eb5
|
4
|
+
data.tar.gz: d154004c62f76f7a99cff3841fbccaf863930c8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 815d1add90cd8a2d5adc0922babfb3de115d098ee0d86f45d77fc6c92b1e996da766c8ecb244cd22939976581dcb70490d493cec53b433b18dbd6d115334570d
|
7
|
+
data.tar.gz: 19f0a0f9f4a7dc0f145df5b21f6a96e0fa5ddf1c8e1194fb6810a40878f7e990847fcd3220e5d097d74d6fb3ca7ce37ca4e45281ca9bdd67ef76f12b592e32a6
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ A gem for processing tasks asynchronously, powered by RabbitMQ.
|
|
8
8
|
## Dependencies
|
9
9
|
|
10
10
|
* Ruby 2.0+
|
11
|
-
* RabbitMQ
|
11
|
+
* RabbitMQ 3.3+
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
@@ -30,19 +30,22 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
### Setup
|
32
32
|
|
33
|
-
|
33
|
+
Configure a logger and your AMQP connection settings as follows. The values defined below are the defaults:
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
SongkickQueue.configure do |config|
|
37
|
-
config.
|
38
|
-
config.
|
39
|
-
config.
|
37
|
+
config.logger = Logger.new(STDOUT)
|
38
|
+
config.host = '127.0.0.1'
|
39
|
+
config.port = 5672
|
40
|
+
config.username = 'guest'
|
41
|
+
config.password = 'guest'
|
42
|
+
config.vhost = '/'
|
40
43
|
end
|
41
44
|
```
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
instance.
|
46
|
+
SongkickQueue should work out the box with a new, locally installed RabbitMQ instance.
|
47
|
+
|
48
|
+
NB. The `vhost` option can be a useful way to isolate environments that share the same RabbitMQ instance (eg. staging and production).
|
46
49
|
|
47
50
|
### Creating consumers
|
48
51
|
|
data/examples/environment.rb
CHANGED
data/examples/producer.rb
CHANGED
data/lib/songkick_queue.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'securerandom'
|
3
|
+
require 'logger'
|
3
4
|
require 'bunny'
|
4
5
|
|
5
6
|
require 'songkick_queue/version'
|
@@ -10,14 +11,25 @@ require 'songkick_queue/worker'
|
|
10
11
|
require 'songkick_queue/cli'
|
11
12
|
|
12
13
|
module SongkickQueue
|
13
|
-
Configuration = Struct.new(
|
14
|
+
Configuration = Struct.new(
|
15
|
+
:logger,
|
16
|
+
:host,
|
17
|
+
:port,
|
18
|
+
:username,
|
19
|
+
:password,
|
20
|
+
:vhost,
|
21
|
+
)
|
22
|
+
|
14
23
|
ConfigurationError = Class.new(StandardError)
|
15
24
|
|
16
25
|
# Retrieve configuration for SongkickQueue
|
17
26
|
#
|
18
27
|
# @return [Configuration]
|
19
28
|
def self.configuration
|
20
|
-
@configuration ||= Configuration.new
|
29
|
+
@configuration ||= Configuration.new(
|
30
|
+
logger: Logger.new(STDOUT),
|
31
|
+
port: 5672,
|
32
|
+
)
|
21
33
|
end
|
22
34
|
|
23
35
|
# Yields a block, passing the memoized configuration instance
|
@@ -25,6 +37,8 @@ module SongkickQueue
|
|
25
37
|
# @yield [Configuration]
|
26
38
|
def self.configure
|
27
39
|
yield(configuration)
|
40
|
+
|
41
|
+
configuration
|
28
42
|
end
|
29
43
|
|
30
44
|
# Publishes the given message to the given queue
|
@@ -21,7 +21,15 @@ module SongkickQueue
|
|
21
21
|
# @return [Bunny::Session]
|
22
22
|
def connection
|
23
23
|
@connection ||= begin
|
24
|
-
connection = Bunny.new(
|
24
|
+
connection = Bunny.new(
|
25
|
+
host: config.host,
|
26
|
+
port: config.port,
|
27
|
+
username: config.username,
|
28
|
+
password: config.password,
|
29
|
+
vhost: config.vhost,
|
30
|
+
heartbeat_interval: 60,
|
31
|
+
)
|
32
|
+
|
25
33
|
connection.start
|
26
34
|
|
27
35
|
connection
|
@@ -30,13 +38,6 @@ module SongkickQueue
|
|
30
38
|
|
31
39
|
private
|
32
40
|
|
33
|
-
# Retrieve the AMQP URL from the configuration
|
34
|
-
#
|
35
|
-
# @raise [ConfigurationError] if not defined
|
36
|
-
def config_amqp
|
37
|
-
config.amqp || fail(ConfigurationError, 'missing AMQP URL from config')
|
38
|
-
end
|
39
|
-
|
40
41
|
def config
|
41
42
|
SongkickQueue.configuration
|
42
43
|
end
|
@@ -16,8 +16,6 @@ module SongkickQueue
|
|
16
16
|
def queue_name
|
17
17
|
@queue_name or fail(NotImplementedError, 'you must declare a queue name to consume from ' +
|
18
18
|
'by calling #consume_from_queue in your consumer class. See README for more info.')
|
19
|
-
|
20
|
-
[config.queue_namespace, @queue_name].compact.join('.')
|
21
19
|
end
|
22
20
|
|
23
21
|
def config
|
@@ -23,13 +23,11 @@ module SongkickQueue
|
|
23
23
|
|
24
24
|
message = JSON.generate(message)
|
25
25
|
|
26
|
-
routing_key = [config.queue_namespace, queue_name].compact.join('.')
|
27
|
-
|
28
26
|
client
|
29
27
|
.default_exchange
|
30
|
-
.publish(message, routing_key:
|
28
|
+
.publish(message, routing_key: String(queue_name))
|
31
29
|
|
32
|
-
logger.info "Published message #{message_id} to '#{
|
30
|
+
logger.info "Published message #{message_id} to '#{queue_name}' at #{produced_at}"
|
33
31
|
end
|
34
32
|
|
35
33
|
private
|
data/songkick_queue.gemspec
CHANGED
@@ -20,18 +20,6 @@ module SongkickQueue
|
|
20
20
|
|
21
21
|
expect(ExampleConsumer.queue_name).to eq 'app.examples'
|
22
22
|
end
|
23
|
-
|
24
|
-
it "should add the configured namespace to the queue name" do
|
25
|
-
class ExampleConsumer
|
26
|
-
include SongkickQueue::Consumer
|
27
|
-
|
28
|
-
consume_from_queue 'app.examples'
|
29
|
-
end
|
30
|
-
|
31
|
-
allow(ExampleConsumer).to receive(:config) { double(queue_namespace: 'test-env') }
|
32
|
-
|
33
|
-
expect(ExampleConsumer.queue_name).to eq 'test-env.app.examples'
|
34
|
-
end
|
35
23
|
end
|
36
24
|
|
37
25
|
describe "#initialize" do
|
@@ -23,29 +23,6 @@ module SongkickQueue
|
|
23
23
|
producer.publish(:queue_name, { example: 'message', value: true },
|
24
24
|
message_id: '92c583bdc248', produced_at: '2015-03-30T15:41:55Z')
|
25
25
|
end
|
26
|
-
|
27
|
-
it "should publish with a routing key using the configured queue namespace" do
|
28
|
-
producer = Producer.new
|
29
|
-
|
30
|
-
exchange = double(:exchange, publish: :published)
|
31
|
-
client = instance_double(Client, default_exchange: exchange)
|
32
|
-
allow(producer).to receive(:client) { client }
|
33
|
-
|
34
|
-
logger = double(:logger, info: true)
|
35
|
-
allow(producer).to receive(:logger) { logger }
|
36
|
-
|
37
|
-
expect(exchange).to receive(:publish)
|
38
|
-
.with('{"message_id":"92c583bdc248","produced_at":"2015-03-30T15:41:55Z",' +
|
39
|
-
'"payload":{"example":"message","value":true}}', routing_key: 'test-env.queue_name')
|
40
|
-
|
41
|
-
expect(logger).to receive(:info)
|
42
|
-
.with("Published message 92c583bdc248 to 'test-env.queue_name' at 2015-03-30T15:41:55Z")
|
43
|
-
|
44
|
-
allow(producer).to receive(:config) { double(queue_namespace: 'test-env') }
|
45
|
-
|
46
|
-
producer.publish(:queue_name, { example: 'message', value: true },
|
47
|
-
message_id: '92c583bdc248', produced_at: '2015-03-30T15:41:55Z')
|
48
|
-
end
|
49
26
|
end
|
50
27
|
end
|
51
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: songkick_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Lucraft
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -71,16 +71,16 @@ dependencies:
|
|
71
71
|
name: bunny
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - '>='
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 1.
|
76
|
+
version: 1.7.0
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: 1.
|
83
|
+
version: 1.7.0
|
84
84
|
description: A gem for processing tasks asynchronously, powered by RabbitMQ.
|
85
85
|
email:
|
86
86
|
- dan.lucraft@songkick.com
|