em-amazon-sqs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +23 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +18 -0
- data/LICENSE +20 -0
- data/README.md +284 -0
- data/Rakefile +57 -0
- data/TODO.md +2 -0
- data/VERSION +1 -0
- data/example/client.rb +22 -0
- data/example/server.rb +27 -0
- data/lib/simple_qs.rb +41 -0
- data/lib/simple_qs/message.rb +135 -0
- data/lib/simple_qs/queue.rb +298 -0
- data/lib/simple_qs/request.rb +24 -0
- data/lib/simple_qs/request/base.rb +105 -0
- data/lib/simple_qs/request/get.rb +14 -0
- data/lib/simple_qs/request/post.rb +14 -0
- data/lib/simple_qs/responce.rb +30 -0
- data/lib/simple_qs/responce/exceptions.rb +39 -0
- data/lib/simple_qs/responce/failure_builder.rb +33 -0
- data/lib/simple_qs/responce/successful_builder.rb +26 -0
- data/lib/version.rb +3 -0
- data/simple_qs.gemspec +24 -0
- data/spec/simple_qs/message_spec.rb +114 -0
- data/spec/simple_qs/queue_spec.rb +145 -0
- data/spec/simple_qs/request_spec.rb +56 -0
- data/spec/simple_qs/responce_spec.rb +118 -0
- data/spec/simple_qs_spec.rb +36 -0
- data/spec/spec_helper.rb +12 -0
- metadata +170 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
## 0.2.1
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
|
5
|
+
- Add missing InvalidClientTokenId error [#1]
|
6
|
+
|
7
|
+
## 0.2
|
8
|
+
|
9
|
+
Features:
|
10
|
+
|
11
|
+
- Add new SQS endpoints
|
12
|
+
- Add new support for MaximumMessageSize, MessageRetentionPeriod attributes for queue
|
13
|
+
|
14
|
+
## 0.1.2
|
15
|
+
|
16
|
+
Features:
|
17
|
+
|
18
|
+
- Add exists? class method to SimpleQS::Queue
|
19
|
+
- Add delete class method to SimpleQS::Queue
|
20
|
+
|
21
|
+
Bugfixes:
|
22
|
+
|
23
|
+
- Fix gemspec, gem now works as it should :)
|
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source :gemcutter
|
2
|
+
|
3
|
+
gem 'ruby-hmac', :require => false
|
4
|
+
gem 'xml-simple'
|
5
|
+
gem 'em-http-request',:git => 'git://github.com/igrigorik/em-http-request.git', :require => 'em-http'
|
6
|
+
gem 'addressable', :require => 'addressable/uri'
|
7
|
+
|
8
|
+
group :test do
|
9
|
+
gem 'rspec'
|
10
|
+
end
|
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Marjan Krekoten'
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
# English #
|
2
|
+
|
3
|
+
## Installation ##
|
4
|
+
|
5
|
+
[sudo] gem install simple_qs
|
6
|
+
|
7
|
+
## Usage ##
|
8
|
+
|
9
|
+
require 'simple_qs'
|
10
|
+
SimpleQS.account_id = 'your-account-id'
|
11
|
+
SimpleQS.access_key_id = 'YOUR_ACCESS_KEY'
|
12
|
+
SimpleQS.secret_access_key = 'YOUR_SECRET_ACCESS_KEY'
|
13
|
+
|
14
|
+
### Region ###
|
15
|
+
|
16
|
+
You can select region for queue:
|
17
|
+
|
18
|
+
# :us_east_1 => 'sqs.us-east-1.amazonaws.com',
|
19
|
+
# :us_west_1 => 'sqs.us-west-1.amazonaws.com',
|
20
|
+
# :eu_west_1 => 'sqs.eu-west-1.amazonaws.com',
|
21
|
+
# :ap_southeast_1 => 'sqs.ap-southeast-1.amazonaws.com'
|
22
|
+
SimpleQS.host # => 'sqs.us-east-1.amazonaws.com'
|
23
|
+
|
24
|
+
SimpleQS.host = :eu_west_1
|
25
|
+
SimpleQS.host # => 'sqs.eu-west-1.amazonaws.com'
|
26
|
+
|
27
|
+
### Queues ###
|
28
|
+
|
29
|
+
Create a queue:
|
30
|
+
|
31
|
+
queue = SimpleQS::Queue.create('queue_name')
|
32
|
+
|
33
|
+
Or:
|
34
|
+
|
35
|
+
SimpleQS::Queue.create('queue_name') do |queue|
|
36
|
+
# ...
|
37
|
+
end
|
38
|
+
|
39
|
+
Create a queue with specific default visibility timeout for received messages:
|
40
|
+
|
41
|
+
SimpleQS::Queue.create('queue_name', 60) # Visibility timeout set to 60 secinds instead of default 30
|
42
|
+
|
43
|
+
List all account's queues:
|
44
|
+
|
45
|
+
SimpleQS::Queue.list # returns list of SimpleQS::Queue objects
|
46
|
+
|
47
|
+
List all account's queues starting with 'test':
|
48
|
+
|
49
|
+
SimpleQS::Queue.list('test')
|
50
|
+
|
51
|
+
Check if queue exists:
|
52
|
+
|
53
|
+
SimpleQS::Queue.exists?('queue_name')
|
54
|
+
|
55
|
+
Change default visibility timeout for queue:
|
56
|
+
|
57
|
+
SimpleQS::Queue.new('queue_name').set_visibility_timeout(120)
|
58
|
+
|
59
|
+
Change maximum message size for queue:
|
60
|
+
|
61
|
+
SimpleQS::Queue.new('queue_name').set_maximum_message_size(65536)
|
62
|
+
|
63
|
+
Change message retention period:
|
64
|
+
|
65
|
+
SimpleQS::Queue.new('queue_name').set_message_retention_period(1209600)
|
66
|
+
|
67
|
+
Set queue attributes:
|
68
|
+
|
69
|
+
SimpleQS::Queue.new('queue_name').set_attributes({:VisibilityTimeout => 120, :Policy => "policy JSON here"})
|
70
|
+
|
71
|
+
Get queue attributes:
|
72
|
+
|
73
|
+
SimpleQS::Queue.new('queue_name').get_attributes(:All)
|
74
|
+
|
75
|
+
Add permissions:
|
76
|
+
|
77
|
+
SimpleQS::Queue.new('queue_name').add_permissions('testPerms', [
|
78
|
+
{:account_id => '098166147350', :action => 'SendMessage'},
|
79
|
+
{:account_id => '098166147350', :action => 'ReceiveMessage'}
|
80
|
+
])
|
81
|
+
|
82
|
+
Remove permissions:
|
83
|
+
|
84
|
+
SimpleQS::Queue.new('queue_name').remove_permissions('testPerms')
|
85
|
+
|
86
|
+
Delete queue:
|
87
|
+
|
88
|
+
SimpleQS::Queue.new('queue_name').delete
|
89
|
+
|
90
|
+
Or:
|
91
|
+
|
92
|
+
SimpleQS::Queue.delete('queue_name')
|
93
|
+
|
94
|
+
### Messages ###
|
95
|
+
|
96
|
+
Send message:
|
97
|
+
|
98
|
+
queue = SimpleQS::Queue.new('queue_name')
|
99
|
+
queue.send_message('message 1')
|
100
|
+
queue.send_message('message 2')
|
101
|
+
|
102
|
+
Or:
|
103
|
+
|
104
|
+
SimpleQS::Message.send(queue, 'message 1')
|
105
|
+
SimpleQS::Message.send(queue, 'message 2')
|
106
|
+
|
107
|
+
Receive message(s):
|
108
|
+
|
109
|
+
queue.receive_messages # always returns array of messages
|
110
|
+
queue.receive_messages(:All, 10, 70) # receive maximum 10 messages with all attributes (:All)
|
111
|
+
# and set for them visibility timeout to 70 seconds
|
112
|
+
|
113
|
+
Or:
|
114
|
+
|
115
|
+
SimpleQS::Message.receive(queue)
|
116
|
+
SimpleQS::Message.receive(queue, :All, 10, 70)
|
117
|
+
|
118
|
+
Resend received message:
|
119
|
+
|
120
|
+
messages = queue.receive_messages
|
121
|
+
messages.first.resend
|
122
|
+
|
123
|
+
Change visibility timeout for this message:
|
124
|
+
|
125
|
+
messages.first.change_visibility(120) # Change to 120 seconds
|
126
|
+
|
127
|
+
Delete received message:
|
128
|
+
|
129
|
+
messages.first.delete
|
130
|
+
|
131
|
+
## TODO ##
|
132
|
+
|
133
|
+
See [TODO](http://github.com/krekoten/SimpleQS/blob/master/TODO.md) file
|
134
|
+
|
135
|
+
## Issues ##
|
136
|
+
|
137
|
+
[ISSUES](http://github.com/krekoten/SimpleQS/issues)
|
138
|
+
|
139
|
+
## Authors ##
|
140
|
+
|
141
|
+
Marjan Krekoten' (krekoten@gmail.com)
|
142
|
+
|
143
|
+
# Українською #
|
144
|
+
|
145
|
+
## Встановлення ##
|
146
|
+
|
147
|
+
[sudo] gem install simple_qs
|
148
|
+
|
149
|
+
## Користування ##
|
150
|
+
|
151
|
+
require 'simple_qs'
|
152
|
+
SimpleQS.account_id = 'your-account-id'
|
153
|
+
SimpleQS.access_key_id = 'YOUR_ACCESS_KEY'
|
154
|
+
|
155
|
+
SimpleQS.secret_access_key = 'YOUR_SECRET_ACCESS_KEY'
|
156
|
+
|
157
|
+
### Регіон ###
|
158
|
+
|
159
|
+
Можна обрати регіон, в якому буде створена черга:
|
160
|
+
|
161
|
+
# :us_east_1 => 'sqs.us-east-1.amazonaws.com',
|
162
|
+
# :us_west_1 => 'sqs.us-west-1.amazonaws.com',
|
163
|
+
# :eu_west_1 => 'sqs.eu-west-1.amazonaws.com',
|
164
|
+
# :ap_southeast_1 => 'sqs.ap-southeast-1.amazonaws.com'
|
165
|
+
SimpleQS.host # => 'sqs.us-east-1.amazonaws.com'
|
166
|
+
|
167
|
+
SimpleQS.host = :eu_west_1
|
168
|
+
SimpleQS.host # => 'sqs.eu-west-1.amazonaws.com'
|
169
|
+
|
170
|
+
### Черги ###
|
171
|
+
|
172
|
+
Створити чергу:
|
173
|
+
|
174
|
+
queue = SimpleQS::Queue.create('queue_name')
|
175
|
+
|
176
|
+
Або:
|
177
|
+
|
178
|
+
SimpleQS::Queue.create('queue_name') do |queue|
|
179
|
+
# ...
|
180
|
+
end
|
181
|
+
|
182
|
+
Створити чергу із специфічним обмеженням часу невидимості для отриманих повідомлень:
|
183
|
+
|
184
|
+
SimpleQS::Queue.create('queue_name', 60) # Час невидимості встановленно на 60 секунд, натомість типових 30-ти
|
185
|
+
|
186
|
+
Перелічити всі черги даного рахунку:
|
187
|
+
|
188
|
+
SimpleQS::Queue.list # returns list of SimpleQS::Queue objects
|
189
|
+
|
190
|
+
Перелічити всі черги даного рахунку, що починаються на 'test':
|
191
|
+
|
192
|
+
SimpleQS::Queue.list('test')
|
193
|
+
|
194
|
+
Перевірити чи черга існує:
|
195
|
+
|
196
|
+
SimpleQS::Queue.exists?('queue_name')
|
197
|
+
|
198
|
+
Змінити типовий час невидимості для даної черги:
|
199
|
+
|
200
|
+
SimpleQS::Queue.new('queue_name').set_visibility_timeout(120)
|
201
|
+
|
202
|
+
Змінити максимальний розмір повідомлення:
|
203
|
+
|
204
|
+
SimpleQS::Queue.new('queue_name').set_maximum_message_size(65536)
|
205
|
+
|
206
|
+
Змінити період зберігання повідомлень для черги:
|
207
|
+
|
208
|
+
SimpleQS::Queue.new('queue_name').set_message_retention_period(1209600)
|
209
|
+
|
210
|
+
Встановити атрибути черги:
|
211
|
+
|
212
|
+
SimpleQS::Queue.new('queue_name').set_attributes({:VisibilityTimeout => 120, :Policy => "policy JSON here"})
|
213
|
+
|
214
|
+
Отримати поточні атрибути черги:
|
215
|
+
|
216
|
+
SimpleQS::Queue.new('queue_name').get_attributes(:All)
|
217
|
+
|
218
|
+
Надати дозволи:
|
219
|
+
|
220
|
+
SimpleQS::Queue.new('queue_name').add_permissions('testPerms', [
|
221
|
+
{:account_id => '098166147350', :action => 'SendMessage'},
|
222
|
+
{:account_id => '098166147350', :action => 'ReceiveMessage'}
|
223
|
+
])
|
224
|
+
|
225
|
+
Скасувати дозволи:
|
226
|
+
|
227
|
+
SimpleQS::Queue.new('queue_name').remove_permissions('testPerms')
|
228
|
+
|
229
|
+
Видалити чергу:
|
230
|
+
|
231
|
+
SimpleQS::Queue.new('queue_name').delete
|
232
|
+
|
233
|
+
Або:
|
234
|
+
|
235
|
+
SimpleQS::Queue.delete('queue_name')
|
236
|
+
|
237
|
+
### Повідомлення ###
|
238
|
+
|
239
|
+
Відправити повідомлення:
|
240
|
+
|
241
|
+
queue = SimpleQS::Queue.new('queue_name')
|
242
|
+
queue.send_message('message 1')
|
243
|
+
queue.send_message('message 2')
|
244
|
+
|
245
|
+
Або:
|
246
|
+
|
247
|
+
SimpleQS::Message.send(queue, 'message 1')
|
248
|
+
SimpleQS::Message.send(queue, 'message 2')
|
249
|
+
|
250
|
+
Отримати повідомлення:
|
251
|
+
|
252
|
+
queue.receive_messages # завжди повертає масив
|
253
|
+
queue.receive_messages(:All, 10, 70) # отримати максимум 10 повідомлень зі всіма атрибутами (:All)
|
254
|
+
# та встановленим часом невидимості у 70 секунд
|
255
|
+
|
256
|
+
Або:
|
257
|
+
|
258
|
+
SimpleQS::Message.receive(queue)
|
259
|
+
SimpleQS::Message.receive(queue, :All, 10, 70)
|
260
|
+
|
261
|
+
Надіслати отримані повідомлення ще раз:
|
262
|
+
|
263
|
+
messages = queue.receive_messages
|
264
|
+
messages.first.resend
|
265
|
+
|
266
|
+
Змінити час невидимості для даного повідомлення:
|
267
|
+
|
268
|
+
messages.first.change_visibility(120) # Встановити у 120 секунд
|
269
|
+
|
270
|
+
Видалити отримане повідомлення з черги:
|
271
|
+
|
272
|
+
messages.first.delete
|
273
|
+
|
274
|
+
## Що потрібно зробити ##
|
275
|
+
|
276
|
+
Дивіться [TODO](http://github.com/krekoten/SimpleQS/blob/master/TODO.md)
|
277
|
+
|
278
|
+
## Помилки, побажання і т.і. ##
|
279
|
+
|
280
|
+
[ISSUES](http://github.com/krekoten/SimpleQS/issues)
|
281
|
+
|
282
|
+
## Автори ##
|
283
|
+
|
284
|
+
Мар'ян Крекотень (krekoten@gmail.com)
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "em-amazon-sqs"
|
8
|
+
gem.summary = %Q{Asyncronous amazon simple queue service}
|
9
|
+
gem.description = %Q{Async amazon simple queue service }
|
10
|
+
gem.email = "jeff.durand@gmail.com"
|
11
|
+
gem.homepage = "https://github.com/johnnyiller/SimpleQS"
|
12
|
+
gem.authors = ["jeff durand"]
|
13
|
+
gem.add_dependency "xml-simple"
|
14
|
+
gem.add_dependency "em-http-request"
|
15
|
+
gem.add_dependency "addressable"
|
16
|
+
gem.add_dependency "ruby-hmac"
|
17
|
+
#gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/test_*.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/test_*.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :test => :check_dependencies
|
46
|
+
|
47
|
+
task :default => :test
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "em-amazon-sqs #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/TODO.md
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/example/client.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
2
|
+
require 'rubygems'
|
3
|
+
require 'lib/simple_qs'
|
4
|
+
|
5
|
+
unless ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] && ENV['AWS_ACCOUNT_ID']
|
6
|
+
abort "Please set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ACCOUNT_ID environment variables"
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleQS.access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
10
|
+
SimpleQS.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
11
|
+
SimpleQS.account_id = ENV['AWS_ACCOUNT_ID']
|
12
|
+
|
13
|
+
@queue = SimpleQS::Queue.create('testMessageBus')
|
14
|
+
|
15
|
+
while true do
|
16
|
+
message = STDIN.gets.chomp
|
17
|
+
@queue.send_message(message)
|
18
|
+
if message == 'quit'
|
19
|
+
puts "Quitting..."
|
20
|
+
break
|
21
|
+
end
|
22
|
+
end
|