la_gear 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -25
- data/la_gear.gemspec +2 -2
- data/lib/la_gear/version.rb +1 -1
- data/test/helper.rb +1 -0
- data/test/test_publisher.rb +14 -16
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ca8da71c32e27e8aabc8d13e7b00c12c5cc6107
|
4
|
+
data.tar.gz: d7eded901af06f3145c15f2395bc959d63f45082
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90cbd481807e189e60dec7c78ff5cd707abdc93c63972077bd1c5efaab3c7659e0c5ab17759bb723cad38b1106826d654a6b64878054626fe3e3b82612034790
|
7
|
+
data.tar.gz: c49890fda1ecbaa23614da07584eb1f456539bb2b34fea737d0eccc5da0ed2a997d70e8aba3453f6660b6a8ac41b4e245d330aa9e2a03eaa96ff442bfedd10c3
|
data/README.md
CHANGED
@@ -30,53 +30,74 @@ Or install it yourself as:
|
|
30
30
|
## Usage
|
31
31
|
|
32
32
|
Instead of `include Sneakers::Worker` in your workers, use `include LaGear::Worker`. Then all of your queues and routing key bindings will automatically use an `Sneakers::Config[:app_name]` plus the class name of your worker as your queue name and the class name of your worker as the routing key. For example,
|
33
|
-
```
|
33
|
+
```ruby
|
34
34
|
Sneakers.configure app_name: 'pogs_are_awesome'
|
35
35
|
|
36
36
|
class BoKnows
|
37
37
|
include LaGear::Worker
|
38
38
|
|
39
39
|
def perform(baseball, football)
|
40
|
-
#
|
40
|
+
# process message ...
|
41
41
|
end
|
42
42
|
end
|
43
43
|
```
|
44
|
-
would by default result in the following 2 queue names:
|
44
|
+
would by default result in the following 2 queue names:
|
45
45
|
|
46
|
-
|
46
|
+
- `pogs_are_awesome.bo_knows`
|
47
|
+
- `pogs_are_awesome.bo_knows.retry`
|
47
48
|
|
48
|
-
|
49
|
+
The default routing key would be: `bo_knows`. This allows for multiple consumer queue bindings for a direct exchange (see the Multiple Bindings section of https://www.rabbitmq.com/tutorials/tutorial-four-ruby.html). The `.retry` is for if you are using [dead letter exchanges](https://www.rabbitmq.com/dlx.html) and [message expirations](https://www.rabbitmq.com/ttl.html) to perform retries (which you should). Just call the `Sneakers::Worker#from_queue` method to override the convention-based defaults like so:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
class PowerRanger
|
53
|
+
include LaGear::Worker
|
49
54
|
|
50
|
-
|
55
|
+
def self.routing_key
|
56
|
+
'bo_knows'
|
57
|
+
end
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
)
|
59
|
+
def self.default_queue_name
|
60
|
+
"#{Sneakers::CONFIG.fetch(:app_name).underscore}.#{name.underscore}"
|
61
|
+
end
|
62
|
+
|
63
|
+
from_queue default_queue_name, default_queue_opts
|
64
|
+
|
65
|
+
def perform(red, yellow)
|
66
|
+
# process message...
|
67
|
+
end
|
59
68
|
end
|
60
|
-
# else Sneakers/Bunny just uses the default RabbitMQ endpoint (amqp://localhost:15672)
|
61
69
|
```
|
62
70
|
|
63
|
-
|
71
|
+
Also, notice in the example above that we don't define a `work` method for `Sneakers::Worker`. That's because `LaGear::Worker` defines it for you. All the method does is deserialize your RabbitMQ message (defaults to JSON) and pass each of the properties as a parameters to Sidekiq's `perform_async` method to process the message. Put your message processing code in a `perform` method instead. That's the method that Sidekiq invokes when it actually processes the message that `LaGear::Worker#work` sent to it.
|
64
72
|
|
65
|
-
|
73
|
+
You can also use the conventions to create versioned workers to more easily handle backwards compatibility when message parameters change. This module/class:
|
66
74
|
|
67
|
-
|
68
|
-
|
69
|
-
class
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
def perform(baseball, football)
|
75
|
-
# ... your worker code ...
|
75
|
+
```ruby
|
76
|
+
module BoKnows
|
77
|
+
class V1
|
78
|
+
def perform
|
79
|
+
# process message...
|
80
|
+
end
|
76
81
|
end
|
77
82
|
end
|
78
83
|
```
|
79
84
|
|
85
|
+
would create the routing key `bo_knows.v1` and these queue names:
|
86
|
+
|
87
|
+
- `pogs_are_awesome.bo_knows.v1`
|
88
|
+
- `pogs_are_awesome.bo_knows.v1.retry`
|
89
|
+
|
90
|
+
### The Bus
|
91
|
+
|
92
|
+
There is also a `LaGear::Bus` class which is an alternative to the `Sneakers::Publisher`. It adds an `opts` parameter to the `publish` method, allowing you to pass the options you would pass to the `bunny` exchange publish [method](http://reference.rubybunny.info/Bunny/Exchange.html#publish-instance_method) (see http://reference.rubybunny.info/Bunny/Exchange.html#publish-instance_method for the list of options). It also allows you use a common way to publish messages:
|
93
|
+
|
94
|
+
- `LaGear::Bus.publish('bo_knows', baseball: 'royals', football: 'cowboys')`
|
95
|
+
- `LaGear::Bus.publish('bo_knows', { baseball: 'royals', football: 'cowboys' }, version: 2)` - will publish to the exchange with the `bo_knows.v2` routing key
|
96
|
+
- `LaGear::Bus.publish_in(1.day, 'bo_knows', baseball: 'royals', football: 'cowboys')`
|
97
|
+
- `LaGear::Bus.publish_at(1.day.from_now, 'bo_knows', baseball: 'royals', football: 'cowboys')`
|
98
|
+
- `LaGear::Bus.publish_local('bo_knows_local', baseball: 'royals', football: 'cowboys')` - this is for local only (`include Sidekiq::Worker`) workers
|
99
|
+
- `LaGear::Bus.publish_local_in('bo_knows', { baseball: 'royals', football: 'cowboys' }, 1.day)`
|
100
|
+
|
80
101
|
## Contributing
|
81
102
|
|
82
103
|
1. Fork it ( https://github.com/[my-github-username]/la_gear/fork )
|
data/la_gear.gemspec
CHANGED
@@ -21,12 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'bunny', '~> 2.2.0'
|
22
22
|
spec.add_dependency 'sneakers', '~> 2.3'
|
23
23
|
spec.add_dependency 'activesupport', '~> 4.2'
|
24
|
-
spec.add_dependency 'sidekiq', '
|
24
|
+
spec.add_dependency 'sidekiq', '>= 3.3'
|
25
25
|
spec.add_dependency 'connection_pool', '~> 2.1'
|
26
26
|
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.4'
|
28
28
|
spec.add_development_dependency 'minitest', '~> 5.7.0'
|
29
29
|
spec.add_development_dependency 'simplecov'
|
30
|
-
spec.add_development_dependency '
|
30
|
+
spec.add_development_dependency 'mocha'
|
31
31
|
spec.add_development_dependency 'pry'
|
32
32
|
end
|
data/lib/la_gear/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/test_publisher.rb
CHANGED
@@ -79,8 +79,6 @@ class TestPublisher < LaGear::Test
|
|
79
79
|
end
|
80
80
|
|
81
81
|
describe 'when serialize is overriden to be a no-op' do
|
82
|
-
require 'rr'
|
83
|
-
|
84
82
|
class PumpItUpPublisher < LaGear::Publisher
|
85
83
|
def self.serialize(msg)
|
86
84
|
msg
|
@@ -96,46 +94,46 @@ class TestPublisher < LaGear::Test
|
|
96
94
|
|
97
95
|
it 'should publish a message to an exchange' do
|
98
96
|
xchg = Object.new
|
99
|
-
|
97
|
+
xchg.expects(:publish).with('test msg', routing_key: 'downloads')
|
100
98
|
|
101
99
|
p = PumpItUpPublisher.new
|
102
100
|
p.instance_variable_set(:@exchange, xchg)
|
103
101
|
|
104
|
-
|
102
|
+
p.stubs(:ensure_connection!)
|
105
103
|
p.publish('test msg', to_queue: 'downloads')
|
106
104
|
end
|
107
105
|
|
108
106
|
it 'should publish with the persistence specified' do
|
109
107
|
xchg = Object.new
|
110
|
-
|
108
|
+
xchg.expects(:publish).with('test msg', routing_key: 'downloads', persistence: true)
|
111
109
|
|
112
110
|
p = PumpItUpPublisher.new
|
113
111
|
p.instance_variable_set(:@exchange, xchg)
|
114
112
|
|
115
|
-
|
113
|
+
p.stubs(:ensure_connection!)
|
116
114
|
p.publish('test msg', to_queue: 'downloads', persistence: true)
|
117
115
|
end
|
118
116
|
|
119
117
|
it 'should publish with arbitrary metadata specified' do
|
120
118
|
xchg = Object.new
|
121
|
-
|
119
|
+
xchg.expects(:publish).with('test msg', routing_key: 'downloads', expiration: 1, headers: { foo: 'bar' })
|
122
120
|
|
123
121
|
p = PumpItUpPublisher.new
|
124
122
|
p.instance_variable_set(:@exchange, xchg)
|
125
123
|
|
126
|
-
|
124
|
+
p.stubs(:ensure_connection!)
|
127
125
|
p.publish('test msg', to_queue: 'downloads', expiration: 1, headers: { foo: 'bar' })
|
128
126
|
end
|
129
127
|
|
130
128
|
it 'should not reconnect if already connected' do
|
131
129
|
xchg = Object.new
|
132
|
-
|
130
|
+
xchg.expects(:publish).with('test msg', routing_key: 'downloads')
|
133
131
|
|
134
132
|
p = PumpItUpPublisher.new
|
135
133
|
p.instance_variable_set(:@exchange, xchg)
|
136
134
|
|
137
|
-
|
138
|
-
|
135
|
+
p.stubs(:connected?).returns(true)
|
136
|
+
p.expects(:ensure_connection!).never
|
139
137
|
|
140
138
|
p.publish('test msg', to_queue: 'downloads')
|
141
139
|
end
|
@@ -151,15 +149,15 @@ class TestPublisher < LaGear::Test
|
|
151
149
|
durable: false)
|
152
150
|
|
153
151
|
channel = Object.new
|
154
|
-
|
155
|
-
|
152
|
+
channel.expects(:exchange).with('another_exchange', type: :topic, durable: false) do
|
153
|
+
Object.new.expects(:publish).with('test msg', routing_key: 'downloads')
|
156
154
|
end
|
157
155
|
|
158
156
|
bunny = Object.new
|
159
|
-
|
160
|
-
|
157
|
+
bunny.expects(:start)
|
158
|
+
bunny.stubs(:create_channel).returns(channel)
|
161
159
|
|
162
|
-
|
160
|
+
Bunny.expects(:new).with('amqp://someuser:somepassword@somehost:5672', heartbeat: 1, vhost: '/', logger: logger).returns bunny
|
163
161
|
|
164
162
|
p = PumpItUpPublisher.new
|
165
163
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: la_gear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Chaney
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
name: sidekiq
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- - "
|
75
|
+
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '3.3'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- - "
|
82
|
+
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '3.3'
|
85
85
|
- !ruby/object:Gem::Dependency
|
@@ -139,7 +139,7 @@ dependencies:
|
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
|
-
name:
|
142
|
+
name: mocha
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
145
|
- - ">="
|