thrift-sqs-transport 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c13edb82ec56a3a0c367216c31b58b09ae57f68d
4
+ data.tar.gz: 6909369605a168b09babe46376b03a6cdd7beafd
5
+ SHA512:
6
+ metadata.gz: a07c4e860b0376dda717cc54609f0de167ec5106cb1386774d523b8beaa3a836b1f32f313ae8cff9930bf9b71419f92a2b318b7cc97b7c93d251e5ab147f8433
7
+ data.tar.gz: 8a7db05bacbaf0ca99ef41dd09133379d2e1f979bc9199b0a935a7d978e0d61158aefbb2b0793d3efd57f23673709dcf9c506e93f06c714a1c299eb9771b63ba
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "thrift"
7
+ gem "fog"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "bundler"
13
+ gem "jeweler", "~> 1.8.4"
14
+ end
@@ -0,0 +1,43 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.0.0)
5
+ excon (0.16.1)
6
+ fog (1.5.0)
7
+ builder
8
+ excon (~> 0.14)
9
+ formatador (~> 0.2.0)
10
+ mime-types
11
+ multi_json (~> 1.0)
12
+ net-scp (~> 1.0.4)
13
+ net-ssh (>= 2.1.3)
14
+ nokogiri (~> 1.5.0)
15
+ ruby-hmac
16
+ formatador (0.2.3)
17
+ git (1.2.5)
18
+ jeweler (1.8.4)
19
+ bundler (~> 1.0)
20
+ git (>= 1.2.5)
21
+ rake
22
+ rdoc
23
+ json (1.7.5)
24
+ mime-types (1.19)
25
+ multi_json (1.3.6)
26
+ net-scp (1.0.4)
27
+ net-ssh (>= 1.99.1)
28
+ net-ssh (2.5.2)
29
+ nokogiri (1.5.5)
30
+ rake (0.9.2.2)
31
+ rdoc (3.12)
32
+ json (~> 1.4)
33
+ ruby-hmac (0.4.0)
34
+ thrift (0.8.0)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler
41
+ fog
42
+ jeweler (~> 1.8.4)
43
+ thrift
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Sean St. Quentin
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 PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL 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.
@@ -0,0 +1,43 @@
1
+ = thrift-sqs-transport
2
+
3
+ A transport for Thrift using Amazon's Simple Queue Service. Its best to use this with a text-based protocol, as SQS rejects data streams from the binary protocols.
4
+
5
+ The Thrift 0.8 gem doesn't contain the JsonProtocol. To use that, see my other gem: thrift-json.
6
+
7
+ = Example
8
+
9
+ struct Message {
10
+ 1: string subject;
11
+ 2: string body;
12
+ }
13
+
14
+ service LoggerService {
15
+ oneway void send_message(1: Message message);
16
+ }
17
+
18
+ == Server Example
19
+
20
+ # The handler class to respond to service calls.
21
+ class LoggerHandler
22
+ def send_message(message)
23
+ puts "I have a message. Here it is: #{message.inspect}"
24
+ end
25
+ end
26
+
27
+ # Setup the server transport. See the source for the options available.
28
+ transport = Thrift::SqsServerTransport.new("my-queue", aws_key, aws_secret, :delete => true)
29
+ handler = LoggerHandler.new
30
+ processor = LoggerService::Processor.new(handler)
31
+ server = Thrift::SimpleServer.new(processor, transport, Thrift::BaseTransportFactory.new, Thrift::JsonProtocolFactory.new)
32
+
33
+ server.serve
34
+
35
+ == Client Example
36
+
37
+ transport = Thrift::SqsTransport.new("my-queue", aws_key, aws_secret)
38
+ protocol = Thrift::JsonProtocol.new(transport)
39
+
40
+ message = Message.new(subject: "Hello", body: "World!")
41
+
42
+ logger = LoggerService::Client.new(protocol)
43
+ logger.send_message(message)
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "thrift-sqs-transport"
18
+ gem.homepage = "http://github.com/elseano/thrift-sqs-transport"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A transport for Thrift using Amazon's Simple Queue Service.}
21
+ gem.description = %Q{A transport for Thrift using Amazon's Simple Queue Service.}
22
+ gem.email = "sean.stquentin@gmail.com"
23
+ gem.authors = ["Sean St. Quentin"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,106 @@
1
+ require 'thrift'
2
+ require 'fog'
3
+
4
+ module Thrift
5
+ class SqsServerTransport < BaseServerTransport
6
+ def initialize(queue_name, aws_key, aws_secret, options = {})
7
+ @queue_name, @aws_key, @aws_secret = queue_name, aws_key, aws_secret
8
+ @options = options
9
+ end
10
+
11
+ def listen
12
+ @transport = SqsTransport.new(@queue_name, @aws_key, @aws_secret, @options)
13
+ end
14
+
15
+ def accept
16
+ @transport
17
+ end
18
+
19
+ def close
20
+ @transport.close if @transport
21
+ end
22
+
23
+ def closed?
24
+ @transport && !@transport.open?
25
+ end
26
+ end
27
+
28
+ class SqsTransport < BaseTransport
29
+
30
+ def initialize(queue_name, aws_key, aws_secret, options = {})
31
+ @queue_name, @aws_key, @aws_secret = queue_name, aws_key, aws_secret
32
+
33
+ @delete_after_read = options[:delete]
34
+ @max_messages = options[:messages_to_read] || 10
35
+ @region = options[:region]
36
+ @host = options[:host]
37
+ end
38
+
39
+ def open
40
+ sqs_options = { :aws_access_key_id => @aws_key, :aws_secret_access_key => @aws_secret }
41
+ sqs_options[:region] = @region if @region
42
+ sqs_options[:host] = @host if @host
43
+
44
+ @connection = Fog::AWS::SQS.new(sqs_options)
45
+ response = @connection.create_queue(@queue_name)
46
+ @queue_url = response.body["QueueUrl"] rescue nil
47
+ @messages = []
48
+ end
49
+
50
+ def close
51
+ @connection = nil
52
+ @queue_url = nil
53
+ @in_buffer = nil
54
+ @out_buffer = nil
55
+ end
56
+
57
+ def open?
58
+ !!@queue_url
59
+ end
60
+
61
+ def read(size)
62
+ open unless open?
63
+
64
+ if @in_buffer
65
+ data_read = @in_buffer.read(size)
66
+
67
+ if data_read.nil?
68
+ @in_buffer = nil
69
+ return read(size)
70
+ else
71
+ return data_read
72
+ end
73
+ else
74
+ @messages += @connection.receive_message(@queue_url, 'MaxNumberOfMessages' => @max_messages).body["Message"] if @messages.length == 0
75
+ return "" if @messages.length == 0
76
+
77
+ message = @messages.shift
78
+
79
+ body = message["Body"]
80
+ receipt = message["ReceiptHandle"]
81
+ @connection.delete_message(@queue_url, receipt) if @delete_after_read
82
+
83
+ if message.length > size
84
+ @in_buffer = StringIO.new(body)
85
+ return @in_buffer.read(size)
86
+ else
87
+ return body
88
+ end
89
+ end
90
+ end
91
+
92
+ def write(data)
93
+ @out_buffer ||= StringIO.new
94
+ @out_buffer.write(data)
95
+ end
96
+
97
+ def flush
98
+ data = @out_buffer.string
99
+ @out_buffer = StringIO.new
100
+
101
+ open unless open?
102
+ @connection.send_message(@queue_url, data)
103
+ end
104
+
105
+ end
106
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thrift-sqs-transport
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean St. Quentin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2012-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thrift
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.4
69
+ description: A transport for Thrift using Amazon's Simple Queue Service.
70
+ email: sean.stquentin@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.rdoc
76
+ files:
77
+ - ".document"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - VERSION
84
+ - lib/thrift-sqs-transport.rb
85
+ homepage: http://github.com/elseano/thrift-sqs-transport
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.3.0
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: A transport for Thrift using Amazon's Simple Queue Service.
109
+ test_files: []