thrifty-bunny 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -1
- data/README.md +3 -1
- data/Rakefile +12 -0
- data/examples/calculator/calculator_server.rb +3 -1
- data/examples/calculator/calculator_service.rb +10 -2
- data/examples/calculator/calculator_service.thrift +5 -1
- data/examples/calculator/calculator_service_constants.rb +9 -0
- data/examples/calculator/calculator_service_types.rb +29 -0
- data/lib/thrifty_bunny/version.rb +1 -1
- data/spec/integration/client_spec.rb +40 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9981672891ec16ef024800ac90c8db849bd095c
|
4
|
+
data.tar.gz: 4d9ba9f1bb935b9d19a2fa52436b6f046da012ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a863b47d7fd30c08a8adbe5424f57105d3fe1cda3c961e1fb3bd3e02a7f38a3572e5ff8edb5f0dfc77bb2b6c1275c23ea5e86f1aea865a1030c7903a559851ac
|
7
|
+
data.tar.gz: 4d851551d98dc06c1abdb2bf70b93a2bc33ed5b9d2526f73aafaa90cbcd6605e2b27f169bbeb3bfd308cbeefd502a0616e54194bf2a1e5292d41c925e10e2efd
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,7 @@ The gem provides a Thrift server that integrates with RabbitMQ. You would use th
|
|
30
30
|
handler = MyHandler.new
|
31
31
|
processor = MyProcessor.new(handler)
|
32
32
|
service = ThriftyBunny::RpcServer.new(processor)
|
33
|
-
service.serve
|
33
|
+
service.serve(log_messages: true)
|
34
34
|
```
|
35
35
|
|
36
36
|
Then you would utilize the included ```ClientTransport``` to connect your Thrift client to RabbitMQ:
|
@@ -56,7 +56,9 @@ Both the ```RpcServer``` and the ```ClientTransport``` accept a ```ThriftyBunny:
|
|
56
56
|
queue | rpc_queue | Name of RabbitMQ queue for the RPC messages
|
57
57
|
exchange | rpc_exchange | Name of the RabbitMQ exchange for the RPC messages
|
58
58
|
|
59
|
+
## Specs
|
59
60
|
|
61
|
+
The specs can be run individually or via a `bundle exec rake spec`. The integration specs require RabbitMQ to be running on the localhost on port 5672. The integration specs will launch the example server, and then exercise the client calls, and the stop the example server.
|
60
62
|
|
61
63
|
## Examples
|
62
64
|
|
data/Rakefile
CHANGED
@@ -4,3 +4,15 @@ begin
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
rescue LoadError # Don't die if rspec not available
|
6
6
|
end
|
7
|
+
|
8
|
+
namespace :generate do
|
9
|
+
|
10
|
+
desc 'Generate ruby example from Thrift file'
|
11
|
+
task :example do
|
12
|
+
outdir = 'examples/calculator'
|
13
|
+
file = "#{outdir}/calculator_service.thrift"
|
14
|
+
%x[thrift -gen rb --out #{outdir} #{file}]
|
15
|
+
puts "Ruby files generated for #{file} to #{outdir}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -5,13 +5,15 @@ module Calculator
|
|
5
5
|
|
6
6
|
class Handler
|
7
7
|
def say_hello(name)
|
8
|
-
puts "Saying hello to #{name}"
|
9
8
|
"Hello, #{name} from Thrift!"
|
10
9
|
end
|
10
|
+
|
11
11
|
def add(value1, value2)
|
12
12
|
value1 + value2
|
13
13
|
end
|
14
|
+
|
14
15
|
def divide(dividend, divisor)
|
16
|
+
raise DivideByZeroException.new("Oops -- you tried to divide by zero; does not work in this universe.") if divisor == 0
|
15
17
|
dividend.to_f / divisor.to_f
|
16
18
|
end
|
17
19
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
#
|
6
6
|
|
7
7
|
require 'thrift'
|
8
|
+
require 'calculator_service_types'
|
8
9
|
|
9
10
|
module CalculatorService
|
10
11
|
class Client
|
@@ -52,6 +53,7 @@ module CalculatorService
|
|
52
53
|
def recv_divide()
|
53
54
|
result = receive_message(Divide_result)
|
54
55
|
return result.success unless result.success.nil?
|
56
|
+
raise result.ex unless result.ex.nil?
|
55
57
|
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'divide failed: unknown result')
|
56
58
|
end
|
57
59
|
|
@@ -91,7 +93,11 @@ module CalculatorService
|
|
91
93
|
def process_divide(seqid, iprot, oprot)
|
92
94
|
args = read_args(iprot, Divide_args)
|
93
95
|
result = Divide_result.new()
|
94
|
-
|
96
|
+
begin
|
97
|
+
result.success = @handler.divide(args.dividend, args.divisor)
|
98
|
+
rescue ::DivideByZeroException => ex
|
99
|
+
result.ex = ex
|
100
|
+
end
|
95
101
|
write_result(result, oprot, 'divide', seqid)
|
96
102
|
end
|
97
103
|
|
@@ -193,9 +199,11 @@ module CalculatorService
|
|
193
199
|
class Divide_result
|
194
200
|
include ::Thrift::Struct, ::Thrift::Struct_Union
|
195
201
|
SUCCESS = 0
|
202
|
+
EX = 1
|
196
203
|
|
197
204
|
FIELDS = {
|
198
|
-
SUCCESS => {:type => ::Thrift::Types::DOUBLE, :name => 'success'}
|
205
|
+
SUCCESS => {:type => ::Thrift::Types::DOUBLE, :name => 'success'},
|
206
|
+
EX => {:type => ::Thrift::Types::STRUCT, :name => 'ex', :class => ::DivideByZeroException}
|
199
207
|
}
|
200
208
|
|
201
209
|
def struct_fields; FIELDS; end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
exception DivideByZeroException {
|
2
|
+
1: string message
|
3
|
+
}
|
4
|
+
|
1
5
|
service CalculatorService {
|
2
6
|
string say_hello(1: string name),
|
3
7
|
i32 add(1: i32 value1, 2: i32 value2),
|
4
|
-
double divide(1: i32 dividend, 2: i32 divisor),
|
8
|
+
double divide(1: i32 dividend, 2: i32 divisor) throws (1: DivideByZeroException ex),
|
5
9
|
void ping()
|
6
10
|
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.1)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
|
9
|
+
class DivideByZeroException < ::Thrift::Exception
|
10
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
11
|
+
def initialize(message=nil)
|
12
|
+
super()
|
13
|
+
self.message = message
|
14
|
+
end
|
15
|
+
|
16
|
+
MESSAGE = 1
|
17
|
+
|
18
|
+
FIELDS = {
|
19
|
+
MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
|
20
|
+
}
|
21
|
+
|
22
|
+
def struct_fields; FIELDS; end
|
23
|
+
|
24
|
+
def validate
|
25
|
+
end
|
26
|
+
|
27
|
+
::Thrift::Struct.generate_accessors self
|
28
|
+
end
|
29
|
+
|
@@ -2,27 +2,60 @@ require 'spec_helper'
|
|
2
2
|
require 'calculator_service'
|
3
3
|
require 'calculator_server'
|
4
4
|
|
5
|
-
describe 'client calls service' do
|
5
|
+
describe 'client calls service to' do
|
6
6
|
|
7
7
|
# Run the server in a forked sub-process
|
8
8
|
def launch_server
|
9
|
-
pid = fork do
|
10
|
-
puts "
|
9
|
+
@pid = fork do
|
10
|
+
Signal.trap("HUP") { puts "Stopping server as planned."; exit }
|
11
|
+
puts "Starting server as planned."
|
11
12
|
server = Calculator::Server.new
|
12
13
|
server.serve
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
before(:
|
17
|
+
before(:all) do
|
17
18
|
launch_server
|
18
|
-
|
19
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:all) do
|
22
|
+
Process.kill("HUP", @pid)
|
23
|
+
end
|
24
|
+
|
25
|
+
def start_client
|
26
|
+
@transport = ThriftyBunny::ClientTransport.new
|
27
|
+
protocol = Thrift::BinaryProtocol.new(@transport)
|
20
28
|
@client = CalculatorService::Client.new(protocol)
|
21
29
|
end
|
22
30
|
|
23
|
-
|
31
|
+
before do
|
32
|
+
start_client
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
@transport.close
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'request ping' do
|
40
|
+
expect {
|
41
|
+
@client.ping
|
42
|
+
}.to_not raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'say hello' do
|
24
46
|
res = @client.say_hello('Bob')
|
25
47
|
expect(res).to eq("Hello, Bob from Thrift!")
|
26
48
|
end
|
27
49
|
|
50
|
+
it 'successfully divide 10 by 5' do
|
51
|
+
res = @client.divide(10, 5)
|
52
|
+
expect(res).to eq(2.0)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'throw a divide by zero exception' do
|
56
|
+
expect {
|
57
|
+
res = @client.divide(10, 0)
|
58
|
+
}.to raise_error(DivideByZeroException)
|
59
|
+
end
|
60
|
+
|
28
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrifty-bunny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Siggelkow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -137,6 +137,8 @@ files:
|
|
137
137
|
- examples/calculator/calculator_server.rb
|
138
138
|
- examples/calculator/calculator_service.rb
|
139
139
|
- examples/calculator/calculator_service.thrift
|
140
|
+
- examples/calculator/calculator_service_constants.rb
|
141
|
+
- examples/calculator/calculator_service_types.rb
|
140
142
|
- examples/calculator/client.start
|
141
143
|
- examples/calculator/server.start
|
142
144
|
- lib/thrifty_bunny.rb
|