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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a1aac7777298d72bae853264f21dc552edc3dad
4
- data.tar.gz: 90d45ace00562b8b6d5db8d0d33ec1c2cfca509d
3
+ metadata.gz: 75d2f489f41e935f1c16ef27861a7d9044472eb5
4
+ data.tar.gz: d154004c62f76f7a99cff3841fbccaf863930c8e
5
5
  SHA512:
6
- metadata.gz: 1abc17c28cf1d98fad5900a7d76c5a5644f436d2257b8a895e2f8243ac816368dbad85cbacf14dc3c1d257ab5b4cc2f7b8e67af2ada6299d14ee9365cb4ee33f
7
- data.tar.gz: 460e390e2dd5f4cf78c067ee7b22a647c884f0b8f3927e10fee635016bd39195092863308eaeef3bfc08822c650298c9b06c3371ac40009fc4637a49cde30625
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 ~v2.8
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
- You must define both the AMQP URL and a logger instance:
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.amqp = 'amqp://localhost:5672' # required
38
- config.logger = Logger.new(STDOUT) # required
39
- config.queue_namespace = ENV['RACK_ENV'] # optional
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
- You can also optionally define a namespace to apply to your queue names automatically when
44
- publishing and consuming. This can be useful to isolate environments that share the same RabbitMQ
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
 
@@ -6,7 +6,7 @@
6
6
  require_relative '../lib/songkick_queue'
7
7
 
8
8
  SongkickQueue.configure do |config|
9
- config.amqp = 'amqp://localhost:5672'
9
+ config.host = 'localhost'
10
10
  config.logger = Logger.new(STDOUT)
11
11
  end
12
12
 
data/examples/producer.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require_relative '../lib/songkick_queue'
2
2
 
3
3
  SongkickQueue.configure do |config|
4
- config.amqp = 'amqp://localhost:5672'
4
+ config.host = 'localhost'
5
5
  config.logger = Logger.new(STDOUT)
6
6
  end
7
7
 
@@ -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(:amqp, :logger, :queue_namespace)
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(config_amqp)
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: routing_key)
28
+ .publish(message, routing_key: String(queue_name))
31
29
 
32
- logger.info "Published message #{message_id} to '#{routing_key}' at #{produced_at}"
30
+ logger.info "Published message #{message_id} to '#{queue_name}' at #{produced_at}"
33
31
  end
34
32
 
35
33
  private
@@ -1,3 +1,3 @@
1
1
  module SongkickQueue
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
  # Used by yardoc for processing README.md code snippets
26
26
  spec.add_development_dependency "redcarpet"
27
27
 
28
- spec.add_dependency "bunny", "~> 1.2.1"
28
+ spec.add_dependency "bunny", ">= 1.7.0"
29
29
  end
@@ -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.3.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-03-31 00:00:00.000000000 Z
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.2.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.2.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