circuitry 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -0
- data/CHANGELOG.md +7 -0
- data/README.md +88 -62
- data/bin/console +4 -4
- data/circuitry.gemspec +12 -11
- data/exe/circuitry +7 -0
- data/lib/circuitry.rb +5 -3
- data/lib/circuitry/cli.rb +70 -0
- data/lib/circuitry/concerns/async.rb +11 -6
- data/lib/circuitry/configuration.rb +16 -9
- data/lib/circuitry/provisioner.rb +59 -0
- data/lib/circuitry/publisher.rb +18 -16
- data/lib/circuitry/queue.rb +27 -0
- data/lib/circuitry/queue_creator.rb +50 -0
- data/lib/circuitry/railtie.rb +9 -0
- data/lib/circuitry/subscriber.rb +56 -37
- data/lib/circuitry/subscription_creator.rb +60 -0
- data/lib/circuitry/tasks.rb +11 -0
- data/lib/circuitry/topic_creator.rb +2 -2
- data/lib/circuitry/version.rb +1 -1
- metadata +72 -45
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'circuitry/services/sns'
|
2
|
+
require 'circuitry/topic'
|
3
|
+
|
4
|
+
module Circuitry
|
5
|
+
class SubscriptionCreator
|
6
|
+
include Services::SNS
|
7
|
+
include Services::SQS
|
8
|
+
|
9
|
+
attr_reader :queue
|
10
|
+
attr_reader :topics
|
11
|
+
|
12
|
+
def self.subscribe_all(queue, topics)
|
13
|
+
new(queue, topics).subscribe_all
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(queue, topics)
|
17
|
+
raise ArgumentError, 'queue must be a Circuitry::Queue' unless queue.is_a?(Circuitry::Queue)
|
18
|
+
raise ArgumentError, 'topics must be an array' unless topics.is_a?(Array)
|
19
|
+
|
20
|
+
@queue = queue
|
21
|
+
@topics = topics
|
22
|
+
end
|
23
|
+
|
24
|
+
def subscribe_all
|
25
|
+
topics.each do |topic|
|
26
|
+
sns.subscribe(topic_arn: topic.arn, endpoint: queue.arn, protocol: 'sqs')
|
27
|
+
end
|
28
|
+
sqs.set_queue_attributes(
|
29
|
+
queue_url: queue.url,
|
30
|
+
attributes: build_policy
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def build_policy
|
37
|
+
# The aws ruby SDK doesn't have a policy builder :{
|
38
|
+
{
|
39
|
+
'Policy' => {
|
40
|
+
'Version' => '2012-10-17',
|
41
|
+
'Id' => '#{queue.arn}/SNSPolicy',
|
42
|
+
'Statement' => topics.map { |t| build_policy_statement(t) }
|
43
|
+
}.to_json
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_policy_statement(topic)
|
48
|
+
{
|
49
|
+
'Sid' => "Sid#{topic.name}",
|
50
|
+
'Effect' => 'Allow',
|
51
|
+
'Principal' => { 'AWS' => '*' },
|
52
|
+
'Action' => 'SQS:SendMessage',
|
53
|
+
'Resource' => queue.arn,
|
54
|
+
'Condition' => {
|
55
|
+
'ArnEquals' => { 'aws:SourceArn' => topic.arn }
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
namespace :circuitry do
|
2
|
+
desc 'Create subscriber queues and subscribe queue to topics'
|
3
|
+
task setup: :environment do
|
4
|
+
require 'circuitry/provisioner'
|
5
|
+
|
6
|
+
logger = Logger.new(STDOUT)
|
7
|
+
logger.level = Logger::INFO
|
8
|
+
|
9
|
+
Circuitry::Provisioner.new(Circuitry.config, logger: logger).run
|
10
|
+
end
|
11
|
+
end
|
@@ -16,10 +16,10 @@ module Circuitry
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def topic
|
19
|
-
return @
|
19
|
+
return @_topic if defined?(@_topic)
|
20
20
|
|
21
21
|
response = sns.create_topic(name: topic_name)
|
22
|
-
@
|
22
|
+
@_topic = Topic.new(response.topic_arn)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/circuitry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuitry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Huggins
|
8
|
+
- Brandon Croft
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
12
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: aws-sdk
|
@@ -52,20 +53,6 @@ dependencies:
|
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '1.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry-byebug
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
56
|
- !ruby/object:Gem::Dependency
|
70
57
|
name: bundler
|
71
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,49 +68,49 @@ dependencies:
|
|
81
68
|
- !ruby/object:Gem::Version
|
82
69
|
version: '1.8'
|
83
70
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
71
|
+
name: codeclimate-test-reporter
|
85
72
|
requirement: !ruby/object:Gem::Requirement
|
86
73
|
requirements:
|
87
|
-
- - "
|
74
|
+
- - ">="
|
88
75
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
76
|
+
version: '0'
|
90
77
|
type: :development
|
91
78
|
prerelease: false
|
92
79
|
version_requirements: !ruby/object:Gem::Requirement
|
93
80
|
requirements:
|
94
|
-
- - "
|
81
|
+
- - ">="
|
95
82
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
83
|
+
version: '0'
|
97
84
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
85
|
+
name: connection_pool
|
99
86
|
requirement: !ruby/object:Gem::Requirement
|
100
87
|
requirements:
|
101
|
-
- - "
|
88
|
+
- - ">="
|
102
89
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
90
|
+
version: '0'
|
104
91
|
type: :development
|
105
92
|
prerelease: false
|
106
93
|
version_requirements: !ruby/object:Gem::Requirement
|
107
94
|
requirements:
|
108
|
-
- - "
|
95
|
+
- - ">="
|
109
96
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
97
|
+
version: '0'
|
111
98
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
99
|
+
name: dalli
|
113
100
|
requirement: !ruby/object:Gem::Requirement
|
114
101
|
requirements:
|
115
|
-
- - "
|
102
|
+
- - ">="
|
116
103
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
104
|
+
version: '0'
|
118
105
|
type: :development
|
119
106
|
prerelease: false
|
120
107
|
version_requirements: !ruby/object:Gem::Requirement
|
121
108
|
requirements:
|
122
|
-
- - "
|
109
|
+
- - ">="
|
123
110
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
111
|
+
version: '0'
|
125
112
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
113
|
+
name: memcache_mock
|
127
114
|
requirement: !ruby/object:Gem::Requirement
|
128
115
|
requirements:
|
129
116
|
- - ">="
|
@@ -137,7 +124,7 @@ dependencies:
|
|
137
124
|
- !ruby/object:Gem::Version
|
138
125
|
version: '0'
|
139
126
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
127
|
+
name: mock_redis
|
141
128
|
requirement: !ruby/object:Gem::Requirement
|
142
129
|
requirements:
|
143
130
|
- - ">="
|
@@ -151,7 +138,7 @@ dependencies:
|
|
151
138
|
- !ruby/object:Gem::Version
|
152
139
|
version: '0'
|
153
140
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
141
|
+
name: pry-byebug
|
155
142
|
requirement: !ruby/object:Gem::Requirement
|
156
143
|
requirements:
|
157
144
|
- - ">="
|
@@ -165,21 +152,21 @@ dependencies:
|
|
165
152
|
- !ruby/object:Gem::Version
|
166
153
|
version: '0'
|
167
154
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
155
|
+
name: rake
|
169
156
|
requirement: !ruby/object:Gem::Requirement
|
170
157
|
requirements:
|
171
|
-
- - "
|
158
|
+
- - "~>"
|
172
159
|
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
160
|
+
version: '10.0'
|
174
161
|
type: :development
|
175
162
|
prerelease: false
|
176
163
|
version_requirements: !ruby/object:Gem::Requirement
|
177
164
|
requirements:
|
178
|
-
- - "
|
165
|
+
- - "~>"
|
179
166
|
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
167
|
+
version: '10.0'
|
181
168
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
169
|
+
name: redis
|
183
170
|
requirement: !ruby/object:Gem::Requirement
|
184
171
|
requirements:
|
185
172
|
- - ">="
|
@@ -193,7 +180,35 @@ dependencies:
|
|
193
180
|
- !ruby/object:Gem::Version
|
194
181
|
version: '0'
|
195
182
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
183
|
+
name: rspec
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - "~>"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '3.2'
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - "~>"
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '3.2'
|
196
|
+
- !ruby/object:Gem::Dependency
|
197
|
+
name: rspec-its
|
198
|
+
requirement: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - "~>"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '1.2'
|
203
|
+
type: :development
|
204
|
+
prerelease: false
|
205
|
+
version_requirements: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - "~>"
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '1.2'
|
210
|
+
- !ruby/object:Gem::Dependency
|
211
|
+
name: thor
|
197
212
|
requirement: !ruby/object:Gem::Requirement
|
198
213
|
requirements:
|
199
214
|
- - ">="
|
@@ -206,15 +221,19 @@ dependencies:
|
|
206
221
|
- - ">="
|
207
222
|
- !ruby/object:Gem::Version
|
208
223
|
version: '0'
|
209
|
-
description:
|
224
|
+
description: A Circuitry publisher application can broadcast events which can be processed
|
225
|
+
independently by Circuitry subscriber applications.
|
210
226
|
email:
|
211
227
|
- matt.huggins@kapost.com
|
212
|
-
|
228
|
+
- brandon@kapost.com
|
229
|
+
executables:
|
230
|
+
- circuitry
|
213
231
|
extensions: []
|
214
232
|
extra_rdoc_files: []
|
215
233
|
files:
|
216
234
|
- ".gitignore"
|
217
235
|
- ".rspec"
|
236
|
+
- ".rubocop.yml"
|
218
237
|
- CHANGELOG.md
|
219
238
|
- Gemfile
|
220
239
|
- LICENSE.txt
|
@@ -224,7 +243,9 @@ files:
|
|
224
243
|
- bin/setup
|
225
244
|
- circle.yml
|
226
245
|
- circuitry.gemspec
|
246
|
+
- exe/circuitry
|
227
247
|
- lib/circuitry.rb
|
248
|
+
- lib/circuitry/cli.rb
|
228
249
|
- lib/circuitry/concerns/async.rb
|
229
250
|
- lib/circuitry/configuration.rb
|
230
251
|
- lib/circuitry/locks/base.rb
|
@@ -237,10 +258,16 @@ files:
|
|
237
258
|
- lib/circuitry/processors/batcher.rb
|
238
259
|
- lib/circuitry/processors/forker.rb
|
239
260
|
- lib/circuitry/processors/threader.rb
|
261
|
+
- lib/circuitry/provisioner.rb
|
240
262
|
- lib/circuitry/publisher.rb
|
263
|
+
- lib/circuitry/queue.rb
|
264
|
+
- lib/circuitry/queue_creator.rb
|
265
|
+
- lib/circuitry/railtie.rb
|
241
266
|
- lib/circuitry/services/sns.rb
|
242
267
|
- lib/circuitry/services/sqs.rb
|
243
268
|
- lib/circuitry/subscriber.rb
|
269
|
+
- lib/circuitry/subscription_creator.rb
|
270
|
+
- lib/circuitry/tasks.rb
|
244
271
|
- lib/circuitry/topic.rb
|
245
272
|
- lib/circuitry/topic_creator.rb
|
246
273
|
- lib/circuitry/version.rb
|
@@ -264,8 +291,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
291
|
version: '0'
|
265
292
|
requirements: []
|
266
293
|
rubyforge_project:
|
267
|
-
rubygems_version: 2.
|
294
|
+
rubygems_version: 2.5.1
|
268
295
|
signing_key:
|
269
296
|
specification_version: 4
|
270
|
-
summary:
|
297
|
+
summary: Decouple ruby applications using Amazon SNS fanout with SQS processing.
|
271
298
|
test_files: []
|