aeden-jruby-typica 0.0.2
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.
- data/.gitignore +2 -0
- data/README.rdoc +3 -0
- data/Rakefile +35 -0
- data/VERSION +1 -0
- data/jruby-typica.gemspec +51 -0
- data/lib/typica.rb +13 -0
- data/lib/typica/sqs.rb +13 -0
- data/lib/typica/sqs/message.rb +27 -0
- data/lib/typica/sqs/queue.rb +66 -0
- data/lib/typica/sqs/queue_service.rb +34 -0
- data/test/integration/sqs_test.rb +65 -0
- data/vendor/commons-codec-1.4.jar +0 -0
- data/vendor/commons-httpclient-3.1.jar +0 -0
- data/vendor/commons-logging-1.1.1.jar +0 -0
- data/vendor/typica.jar +0 -0
- metadata +68 -0
data/.gitignore
ADDED
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
|
4
|
+
desc 'Default: run tests.'
|
5
|
+
task :default => [:test]
|
6
|
+
|
7
|
+
desc 'Run tests.'
|
8
|
+
task :test do
|
9
|
+
require File.dirname(__FILE__) + '/test/integration/sqs_test'
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'Generate documentation.'
|
13
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
14
|
+
rdoc.rdoc_dir = 'rdoc'
|
15
|
+
rdoc.title = 'JRuby Typica'
|
16
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
17
|
+
rdoc.rdoc_files.include('README.rdoc')
|
18
|
+
rdoc.rdoc_files.include('lib/*.rb')
|
19
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
require 'jeweler'
|
24
|
+
Jeweler::Tasks.new do |gemspec|
|
25
|
+
gemspec.name = "jruby-typica"
|
26
|
+
gemspec.summary = "JRuby wrapper for Typica."
|
27
|
+
gemspec.email = "anthonyeden@gmail.com"
|
28
|
+
gemspec.homepage = "http://github.com/aeden/jruby-typica"
|
29
|
+
gemspec.description = "JRuby wrapper for the Typica Java library, which provides interfaces to Amazon Web Services."
|
30
|
+
gemspec.authors = ["Anthony Eden"]
|
31
|
+
gemspec.files.exclude 'docs/**/*'
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
35
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{jruby-typica}
|
5
|
+
s.version = "0.0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Anthony Eden"]
|
9
|
+
s.date = %q{2009-08-12}
|
10
|
+
s.description = %q{JRuby wrapper for the Typica Java library, which provides interfaces to Amazon Web Services.}
|
11
|
+
s.email = %q{anthonyeden@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"README.rdoc",
|
18
|
+
"Rakefile",
|
19
|
+
"VERSION",
|
20
|
+
"jruby-typica.gemspec",
|
21
|
+
"lib/typica.rb",
|
22
|
+
"lib/typica/sqs.rb",
|
23
|
+
"lib/typica/sqs/message.rb",
|
24
|
+
"lib/typica/sqs/queue.rb",
|
25
|
+
"lib/typica/sqs/queue_service.rb",
|
26
|
+
"test/integration/sqs_test.rb",
|
27
|
+
"vendor/commons-codec-1.4.jar",
|
28
|
+
"vendor/commons-httpclient-3.1.jar",
|
29
|
+
"vendor/commons-logging-1.1.1.jar",
|
30
|
+
"vendor/typica.jar"
|
31
|
+
]
|
32
|
+
s.has_rdoc = true
|
33
|
+
s.homepage = %q{http://github.com/aeden/jruby-typica}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.1}
|
37
|
+
s.summary = %q{JRuby wrapper for Typica.}
|
38
|
+
s.test_files = [
|
39
|
+
"test/integration/sqs_test.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 2
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
else
|
48
|
+
end
|
49
|
+
else
|
50
|
+
end
|
51
|
+
end
|
data/lib/typica.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'java'
|
2
|
+
require File.dirname(__FILE__) + '/../vendor/commons-httpclient-3.1.jar'
|
3
|
+
require File.dirname(__FILE__) + '/../vendor/commons-logging-1.1.1.jar'
|
4
|
+
require File.dirname(__FILE__) + '/../vendor/commons-codec-1.4.jar'
|
5
|
+
require File.dirname(__FILE__) + '/../vendor/typica.jar'
|
6
|
+
|
7
|
+
# The Ruby module that contains wrappers for the Java Typica project.
|
8
|
+
module Typica
|
9
|
+
end
|
10
|
+
|
11
|
+
$:.unshift(File.dirname(__FILE__))
|
12
|
+
|
13
|
+
require 'typica/sqs'
|
data/lib/typica/sqs.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Typica #:nodoc:
|
2
|
+
# The SQS module provides an SQS wrapper around the Typica
|
3
|
+
# SQS implementation.
|
4
|
+
module Sqs
|
5
|
+
# An SQS error
|
6
|
+
class SqsError < RuntimeError
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'typica/sqs/queue_service'
|
12
|
+
require 'typica/sqs/queue'
|
13
|
+
require 'typica/sqs/message'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Typica #:nodoc:
|
2
|
+
module Sqs #:nodoc:
|
3
|
+
# A single SQS message.
|
4
|
+
class Message
|
5
|
+
def initialize(message_impl, queue_impl) #:nodoc:
|
6
|
+
@message_impl = message_impl
|
7
|
+
@queue_impl = queue_impl
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get the ID of the message
|
11
|
+
def id
|
12
|
+
@message_impl.message_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get the message body text.
|
16
|
+
def body
|
17
|
+
@message_impl.message_body
|
18
|
+
end
|
19
|
+
|
20
|
+
# Delete this message from the queue.
|
21
|
+
def delete
|
22
|
+
@queue_impl.delete_message(@message_impl)
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Typica #:nodoc:
|
2
|
+
module Sqs #:nodoc:
|
3
|
+
# An SQS queue.
|
4
|
+
class Queue
|
5
|
+
def initialize(queue_impl) #:nodoc:
|
6
|
+
@queue_impl = queue_impl
|
7
|
+
end
|
8
|
+
|
9
|
+
# Get the queue name
|
10
|
+
def name
|
11
|
+
url.path.gsub(/\/\d+\//, '')
|
12
|
+
end
|
13
|
+
|
14
|
+
# Get the full queue url
|
15
|
+
def url
|
16
|
+
@queue_impl.url
|
17
|
+
end
|
18
|
+
|
19
|
+
# Delete the queue.
|
20
|
+
def delete
|
21
|
+
@queue_impl.delete_queue
|
22
|
+
end
|
23
|
+
|
24
|
+
# Receive a single message from the queue. If no visibility timeout
|
25
|
+
# is provided then the value of 30 seconds will be used.
|
26
|
+
def receive(visibility_timeout=nil)
|
27
|
+
message = if visibility_timeout
|
28
|
+
@queue_impl.receive_message(visibility_timeout)
|
29
|
+
else
|
30
|
+
@queue_impl.receive_message
|
31
|
+
end
|
32
|
+
|
33
|
+
Message.new(message, @queue_impl) if message
|
34
|
+
end
|
35
|
+
|
36
|
+
# Receive multiple messages from the queue
|
37
|
+
def receive_messages(number_of_messages=1, visibility_timeout=nil)
|
38
|
+
messages = if visibility_timeout
|
39
|
+
@queue_impl.receive_messages(number_of_messages, visibility_timeout)
|
40
|
+
else
|
41
|
+
@queue_impl.receive_messages(number_of_messages)
|
42
|
+
end
|
43
|
+
|
44
|
+
messages.map { |message| Message.new(message, @queue_impl) }
|
45
|
+
end
|
46
|
+
|
47
|
+
# Send a message to the queue
|
48
|
+
def send_message(message)
|
49
|
+
@queue_impl.send_message(message)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get the approximate number of messages in the queue.
|
53
|
+
def size
|
54
|
+
@queue_impl.approximate_number_of_messages
|
55
|
+
end
|
56
|
+
|
57
|
+
def visibility_timeout
|
58
|
+
@queue_impl.visibility_timeout
|
59
|
+
end
|
60
|
+
|
61
|
+
def visibility_timeout=(visibility_timeout)
|
62
|
+
@queue_impl.visibility_timeout = visibility_timeout
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Typica
|
2
|
+
module Sqs
|
3
|
+
class QueueService
|
4
|
+
# Initialize the queue server with the given access key id and
|
5
|
+
# secret access key.
|
6
|
+
def initialize(aws_access_key_id, aws_secret_access_key, options={})
|
7
|
+
@queue_service_impl = com.xerox.amazonws.sqs2.QueueService.new(
|
8
|
+
aws_access_key_id, aws_secret_access_key
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get a list of all of the Queues.
|
13
|
+
def queues
|
14
|
+
@queue_service_impl.list_message_queues(nil).map { |queue|
|
15
|
+
Queue.new(queue)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get the queue by name.
|
20
|
+
def queue(name, create=true)
|
21
|
+
if create
|
22
|
+
begin
|
23
|
+
Queue.new(@queue_service_impl.get_or_create_message_queue(name))
|
24
|
+
rescue com.xerox.amazonws.sqs2.SQSException => e
|
25
|
+
raise Typica::Sqs::SqsError.new(e.message)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
queue = @queue_service_impl.get_message_queue(name)
|
29
|
+
Queue.new(queue) if queue
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'lib/typica'
|
3
|
+
|
4
|
+
module Integration
|
5
|
+
class SqsTest < Test::Unit::TestCase
|
6
|
+
def test_sqs
|
7
|
+
queue_service = Typica::Sqs::QueueService.new(
|
8
|
+
ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']
|
9
|
+
)
|
10
|
+
|
11
|
+
puts "Listing Queues:"
|
12
|
+
queues = queue_service.queues
|
13
|
+
assert_not_nil queues
|
14
|
+
assert queues.length > 1
|
15
|
+
queues.each do |queue|
|
16
|
+
puts "#{queue.url} (#{queue.name})"
|
17
|
+
end
|
18
|
+
|
19
|
+
puts "Getting 'typica_test' Queue:"
|
20
|
+
queue = queue_service.queue('typica_test')
|
21
|
+
puts "#{queue.url} (#{queue.name})"
|
22
|
+
assert_not_nil queue
|
23
|
+
assert_equal 'typica_test', queue.name
|
24
|
+
|
25
|
+
puts "#{queue.name} approx msg count: #{queue.size}"
|
26
|
+
assert_equal 0, queue.size
|
27
|
+
|
28
|
+
puts "Sending a message"
|
29
|
+
body = "message sent at #{Time.now}"
|
30
|
+
puts queue.send_message(body)
|
31
|
+
|
32
|
+
puts "Sleeping 2 seconds"
|
33
|
+
sleep(2)
|
34
|
+
|
35
|
+
puts "Receiving messages one-by-one"
|
36
|
+
while(message = queue.receive)
|
37
|
+
puts "Received message #{message.id}"
|
38
|
+
puts message.body
|
39
|
+
assert_equal body, message.body
|
40
|
+
|
41
|
+
puts "Deleting message #{message.id}"
|
42
|
+
message.delete
|
43
|
+
end
|
44
|
+
|
45
|
+
puts "Sending 10 messages"
|
46
|
+
0.upto(10) do |i|
|
47
|
+
queue.send_message("message #{i} sent at #{Time.now}")
|
48
|
+
end
|
49
|
+
|
50
|
+
puts "Sleeping for 10 seconds"
|
51
|
+
sleep(10)
|
52
|
+
|
53
|
+
puts "Receiving 10 messages from the queue"
|
54
|
+
messages = queue.receive_messages(10)
|
55
|
+
puts "Received #{messages.length} messages"
|
56
|
+
|
57
|
+
messages.each do |message|
|
58
|
+
message.delete
|
59
|
+
end
|
60
|
+
|
61
|
+
puts "Deleting the queue"
|
62
|
+
queue.delete
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
data/vendor/typica.jar
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aeden-jruby-typica
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anthony Eden
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-12 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: JRuby wrapper for the Typica Java library, which provides interfaces to Amazon Web Services.
|
17
|
+
email: anthonyeden@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- README.rdoc
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- jruby-typica.gemspec
|
30
|
+
- lib/typica.rb
|
31
|
+
- lib/typica/sqs.rb
|
32
|
+
- lib/typica/sqs/message.rb
|
33
|
+
- lib/typica/sqs/queue.rb
|
34
|
+
- lib/typica/sqs/queue_service.rb
|
35
|
+
- test/integration/sqs_test.rb
|
36
|
+
- vendor/commons-codec-1.4.jar
|
37
|
+
- vendor/commons-httpclient-3.1.jar
|
38
|
+
- vendor/commons-logging-1.1.1.jar
|
39
|
+
- vendor/typica.jar
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/aeden/jruby-typica
|
42
|
+
licenses:
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: JRuby wrapper for Typica.
|
67
|
+
test_files:
|
68
|
+
- test/integration/sqs_test.rb
|