sqs_bunny 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/sqs_bunny +8 -0
- data/lib/sqs_bunny.rb +65 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4840b44a6e5e0d7e33982d7fca3f337d80bf7e0e
|
4
|
+
data.tar.gz: da5949d3acde4b48ed0bc29dcc18e5af942d4392
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16d1d851796670d9f1064e003abdf25ec94c112cd13ddeee84d1e6815ffda001f1f239825e6384750dbdf010aa39e955791979ebc46053ea2ec2eb1eacc29d95
|
7
|
+
data.tar.gz: 849ea8e7fe91062af64d456bdbce85125ae205430113e69d2918bda2a3109b025a19a97e7364390bf4de56447a83c9ff435829b9da2a115e8ac6152056865704
|
data/bin/sqs_bunny
ADDED
data/lib/sqs_bunny.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'aws-sdk-core'
|
3
|
+
##
|
4
|
+
# Main execution class, just call +SqsBunny.run+ and pass in the path of your configuration file
|
5
|
+
|
6
|
+
class SqsBunny
|
7
|
+
attr_accessor :logger
|
8
|
+
##
|
9
|
+
# Run this method to start the job, optionally pass in a configuration hash. Otherwise
|
10
|
+
# the job will look for a JSON configuration at +config/setup.json+
|
11
|
+
def self.run config_file_path, logger=nil
|
12
|
+
raise "Configuration file could not be found at #{config_file_path}" unless File.exists? config_file_path
|
13
|
+
s = self.new(JSON.parse(IO.read(config_file_path)))
|
14
|
+
s.logger = logger
|
15
|
+
s.go
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize config
|
19
|
+
@config = {'wait_time_seconds'=>10}.merge config
|
20
|
+
@poll_count = 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def go
|
24
|
+
while true
|
25
|
+
@poll_count += 1
|
26
|
+
client = Aws::SQS::Client.new
|
27
|
+
parent_url = @config['parent_q']['queue_url']
|
28
|
+
log.debug "Polling for messages at #{parent_url}"
|
29
|
+
resp = client.receive_message(queue_url:parent_url,wait_time_seconds:@config['wait_time_seconds'])
|
30
|
+
if resp.respond_to? :messages
|
31
|
+
resp.messages.each do |x|
|
32
|
+
log.info x.body
|
33
|
+
send_message client, x
|
34
|
+
client.delete_message(queue_url:parent_url,receipt_handle:x.receipt_handle)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
log.debug "No messages"
|
38
|
+
end
|
39
|
+
break unless keep_polling?
|
40
|
+
sleep 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
#private stuff
|
45
|
+
def send_message client, message
|
46
|
+
return unless @config['children']
|
47
|
+
@config['children'].each do |child|
|
48
|
+
client.send_message(queue_url:child['queue_url'],message_body:message.body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
def keep_polling?
|
52
|
+
@config['poll_max'].nil? || @poll_count < @config['poll_max']
|
53
|
+
end
|
54
|
+
class NullLogger < Logger
|
55
|
+
def initialize(*args)
|
56
|
+
end
|
57
|
+
|
58
|
+
def add(*args, &block)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
def log
|
62
|
+
@logger ||= NullLogger.new
|
63
|
+
end
|
64
|
+
private :keep_polling?; :log
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sqs_bunny
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Glick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.beta
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.beta
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
41
|
+
description: Polls a single SQS queue and copies the body of any messages to a configurable
|
42
|
+
set of child queues then deletes the message from the parent.
|
43
|
+
email: brian@brian-glick.com
|
44
|
+
executables:
|
45
|
+
- sqs_bunny
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- bin/sqs_bunny
|
50
|
+
- lib/sqs_bunny.rb
|
51
|
+
homepage: https://github.com/Vandegrift/sqs_bunny
|
52
|
+
licenses:
|
53
|
+
- Apache 2.0
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.2.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Copy Amazon SQS messages from one master queue to multiple child queues
|
75
|
+
test_files: []
|