thrifty-bunny 0.0.1 → 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.
- checksums.yaml +4 -4
- data/examples/calculator/bin/client.start +54 -0
- data/examples/calculator/bin/server.start +7 -0
- data/examples/calculator/calculator_service.rb +240 -0
- data/examples/calculator/calculator_service.thrift +6 -0
- data/examples/{hello_thrift → calculator}/client.rb +30 -30
- data/examples/{hello_thrift → calculator}/server.rb +13 -4
- data/lib/thrifty_bunny/version.rb +1 -1
- metadata +8 -10
- data/examples/bin/client.start +0 -14
- data/examples/bin/server.start +0 -7
- data/examples/hello_thrift/hello_service/hello_service.rb +0 -78
- data/examples/hello_thrift/hello_service/hello_service_constants.rb +0 -9
- data/examples/hello_thrift/hello_service/hello_service_types.rb +0 -8
- data/examples/hello_thrift/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afc0cfa4351b9c951f34dd900bf68be502a346c9
|
4
|
+
data.tar.gz: 6d8488899ba2e362152f06c2dddba845e4aa0a71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 598b2b4cb8347215d838d2f42a9f878accde86b922dc62f340b8b14cfe8cad01271d4c3109b23bd5af8c003cc66b27d665dd5f8fc0f93e74ef9bcb71b67b9c35
|
7
|
+
data.tar.gz: 3488a12679385b6c25e7c52d38c79272964078f920bda0b78d1b6816fb029841a3c0bca92653a1db56fac932e2a525fcf2f056c3894c7d79574ceea2c318a9c9
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../client'
|
3
|
+
|
4
|
+
class ClientCli
|
5
|
+
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def say_hello
|
13
|
+
print "Say Hello: What is your name? "
|
14
|
+
input = gets.strip
|
15
|
+
puts client.say_hello(input)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add
|
19
|
+
print "Add: What is the first value? "
|
20
|
+
value1 = gets.strip.to_i
|
21
|
+
print "Add: What is the second value? "
|
22
|
+
value2 = gets.strip.to_i
|
23
|
+
puts client.add(value1, value2)
|
24
|
+
end
|
25
|
+
|
26
|
+
def divide
|
27
|
+
print "Divide: What is the dividend? "
|
28
|
+
dividend = gets.strip.to_i
|
29
|
+
print "Add: What is the divisor? "
|
30
|
+
divisor = gets.strip.to_i
|
31
|
+
puts client.divide(dividend, divisor)
|
32
|
+
end
|
33
|
+
|
34
|
+
def ping
|
35
|
+
print "Send ping?"
|
36
|
+
input = gets.strip
|
37
|
+
if input =~ /^y/i
|
38
|
+
client.ping
|
39
|
+
puts "Success!"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
transport = ThriftyBunny::ClientTransport.new
|
45
|
+
protocol = Thrift::BinaryProtocol.new(transport)
|
46
|
+
client = Calculator::Client.new(protocol)
|
47
|
+
client_cli = ClientCli.new(client)
|
48
|
+
|
49
|
+
loop do
|
50
|
+
client_cli.add
|
51
|
+
client_cli.say_hello
|
52
|
+
client_cli.ping
|
53
|
+
client_cli.divide
|
54
|
+
end
|
@@ -0,0 +1,240 @@
|
|
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
|
+
module CalculatorService
|
10
|
+
class Client
|
11
|
+
include ::Thrift::Client
|
12
|
+
|
13
|
+
def say_hello(name)
|
14
|
+
send_say_hello(name)
|
15
|
+
return recv_say_hello()
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_say_hello(name)
|
19
|
+
send_message('say_hello', Say_hello_args, :name => name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def recv_say_hello()
|
23
|
+
result = receive_message(Say_hello_result)
|
24
|
+
return result.success unless result.success.nil?
|
25
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'say_hello failed: unknown result')
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(value1, value2)
|
29
|
+
send_add(value1, value2)
|
30
|
+
return recv_add()
|
31
|
+
end
|
32
|
+
|
33
|
+
def send_add(value1, value2)
|
34
|
+
send_message('add', Add_args, :value1 => value1, :value2 => value2)
|
35
|
+
end
|
36
|
+
|
37
|
+
def recv_add()
|
38
|
+
result = receive_message(Add_result)
|
39
|
+
return result.success unless result.success.nil?
|
40
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'add failed: unknown result')
|
41
|
+
end
|
42
|
+
|
43
|
+
def divide(dividend, divisor)
|
44
|
+
send_divide(dividend, divisor)
|
45
|
+
return recv_divide()
|
46
|
+
end
|
47
|
+
|
48
|
+
def send_divide(dividend, divisor)
|
49
|
+
send_message('divide', Divide_args, :dividend => dividend, :divisor => divisor)
|
50
|
+
end
|
51
|
+
|
52
|
+
def recv_divide()
|
53
|
+
result = receive_message(Divide_result)
|
54
|
+
return result.success unless result.success.nil?
|
55
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'divide failed: unknown result')
|
56
|
+
end
|
57
|
+
|
58
|
+
def ping()
|
59
|
+
send_ping()
|
60
|
+
recv_ping()
|
61
|
+
end
|
62
|
+
|
63
|
+
def send_ping()
|
64
|
+
send_message('ping', Ping_args)
|
65
|
+
end
|
66
|
+
|
67
|
+
def recv_ping()
|
68
|
+
result = receive_message(Ping_result)
|
69
|
+
return
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
class Processor
|
75
|
+
include ::Thrift::Processor
|
76
|
+
|
77
|
+
def process_say_hello(seqid, iprot, oprot)
|
78
|
+
args = read_args(iprot, Say_hello_args)
|
79
|
+
result = Say_hello_result.new()
|
80
|
+
result.success = @handler.say_hello(args.name)
|
81
|
+
write_result(result, oprot, 'say_hello', seqid)
|
82
|
+
end
|
83
|
+
|
84
|
+
def process_add(seqid, iprot, oprot)
|
85
|
+
args = read_args(iprot, Add_args)
|
86
|
+
result = Add_result.new()
|
87
|
+
result.success = @handler.add(args.value1, args.value2)
|
88
|
+
write_result(result, oprot, 'add', seqid)
|
89
|
+
end
|
90
|
+
|
91
|
+
def process_divide(seqid, iprot, oprot)
|
92
|
+
args = read_args(iprot, Divide_args)
|
93
|
+
result = Divide_result.new()
|
94
|
+
result.success = @handler.divide(args.dividend, args.divisor)
|
95
|
+
write_result(result, oprot, 'divide', seqid)
|
96
|
+
end
|
97
|
+
|
98
|
+
def process_ping(seqid, iprot, oprot)
|
99
|
+
args = read_args(iprot, Ping_args)
|
100
|
+
result = Ping_result.new()
|
101
|
+
@handler.ping()
|
102
|
+
write_result(result, oprot, 'ping', seqid)
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
108
|
+
|
109
|
+
class Say_hello_args
|
110
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
111
|
+
NAME = 1
|
112
|
+
|
113
|
+
FIELDS = {
|
114
|
+
NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}
|
115
|
+
}
|
116
|
+
|
117
|
+
def struct_fields; FIELDS; end
|
118
|
+
|
119
|
+
def validate
|
120
|
+
end
|
121
|
+
|
122
|
+
::Thrift::Struct.generate_accessors self
|
123
|
+
end
|
124
|
+
|
125
|
+
class Say_hello_result
|
126
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
127
|
+
SUCCESS = 0
|
128
|
+
|
129
|
+
FIELDS = {
|
130
|
+
SUCCESS => {:type => ::Thrift::Types::STRING, :name => 'success'}
|
131
|
+
}
|
132
|
+
|
133
|
+
def struct_fields; FIELDS; end
|
134
|
+
|
135
|
+
def validate
|
136
|
+
end
|
137
|
+
|
138
|
+
::Thrift::Struct.generate_accessors self
|
139
|
+
end
|
140
|
+
|
141
|
+
class Add_args
|
142
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
143
|
+
VALUE1 = 1
|
144
|
+
VALUE2 = 2
|
145
|
+
|
146
|
+
FIELDS = {
|
147
|
+
VALUE1 => {:type => ::Thrift::Types::I32, :name => 'value1'},
|
148
|
+
VALUE2 => {:type => ::Thrift::Types::I32, :name => 'value2'}
|
149
|
+
}
|
150
|
+
|
151
|
+
def struct_fields; FIELDS; end
|
152
|
+
|
153
|
+
def validate
|
154
|
+
end
|
155
|
+
|
156
|
+
::Thrift::Struct.generate_accessors self
|
157
|
+
end
|
158
|
+
|
159
|
+
class Add_result
|
160
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
161
|
+
SUCCESS = 0
|
162
|
+
|
163
|
+
FIELDS = {
|
164
|
+
SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success'}
|
165
|
+
}
|
166
|
+
|
167
|
+
def struct_fields; FIELDS; end
|
168
|
+
|
169
|
+
def validate
|
170
|
+
end
|
171
|
+
|
172
|
+
::Thrift::Struct.generate_accessors self
|
173
|
+
end
|
174
|
+
|
175
|
+
class Divide_args
|
176
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
177
|
+
DIVIDEND = 1
|
178
|
+
DIVISOR = 2
|
179
|
+
|
180
|
+
FIELDS = {
|
181
|
+
DIVIDEND => {:type => ::Thrift::Types::I32, :name => 'dividend'},
|
182
|
+
DIVISOR => {:type => ::Thrift::Types::I32, :name => 'divisor'}
|
183
|
+
}
|
184
|
+
|
185
|
+
def struct_fields; FIELDS; end
|
186
|
+
|
187
|
+
def validate
|
188
|
+
end
|
189
|
+
|
190
|
+
::Thrift::Struct.generate_accessors self
|
191
|
+
end
|
192
|
+
|
193
|
+
class Divide_result
|
194
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
195
|
+
SUCCESS = 0
|
196
|
+
|
197
|
+
FIELDS = {
|
198
|
+
SUCCESS => {:type => ::Thrift::Types::DOUBLE, :name => 'success'}
|
199
|
+
}
|
200
|
+
|
201
|
+
def struct_fields; FIELDS; end
|
202
|
+
|
203
|
+
def validate
|
204
|
+
end
|
205
|
+
|
206
|
+
::Thrift::Struct.generate_accessors self
|
207
|
+
end
|
208
|
+
|
209
|
+
class Ping_args
|
210
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
211
|
+
|
212
|
+
FIELDS = {
|
213
|
+
|
214
|
+
}
|
215
|
+
|
216
|
+
def struct_fields; FIELDS; end
|
217
|
+
|
218
|
+
def validate
|
219
|
+
end
|
220
|
+
|
221
|
+
::Thrift::Struct.generate_accessors self
|
222
|
+
end
|
223
|
+
|
224
|
+
class Ping_result
|
225
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
226
|
+
|
227
|
+
FIELDS = {
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
def struct_fields; FIELDS; end
|
232
|
+
|
233
|
+
def validate
|
234
|
+
end
|
235
|
+
|
236
|
+
::Thrift::Struct.generate_accessors self
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
@@ -1,34 +1,34 @@
|
|
1
1
|
require 'thrifty_bunny'
|
2
|
-
require_relative '
|
3
|
-
|
4
|
-
module
|
5
|
-
|
6
|
-
class Client
|
7
|
-
|
8
|
-
def initialize(options={})
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def say_hello(name)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def safe_transport
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
2
|
+
require_relative 'calculator_service'
|
3
|
+
|
4
|
+
module Calculator
|
5
|
+
|
6
|
+
class Client < CalculatorService::Client
|
7
|
+
|
8
|
+
# def initialize(options={})
|
9
|
+
# @transport = ThriftyBunny::ClientTransport.new
|
10
|
+
# protocol = Thrift::BinaryProtocol.new(@transport)
|
11
|
+
# @client = CalculatorService::Client.new(protocol)
|
12
|
+
# end
|
13
|
+
|
14
|
+
# def say_hello(name)
|
15
|
+
# safe_transport do
|
16
|
+
# @client.say_hello(name)
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
|
20
|
+
# private
|
21
|
+
|
22
|
+
# def safe_transport
|
23
|
+
# begin
|
24
|
+
# @transport.open
|
25
|
+
# return yield
|
26
|
+
# rescue ThriftyBunny::ResponseTimeout => e
|
27
|
+
# puts e
|
28
|
+
# ensure
|
29
|
+
# @transport.close
|
30
|
+
# end
|
31
|
+
# end
|
32
32
|
|
33
33
|
# def send_message(name, args_class, args = {})
|
34
34
|
# @oprot.write_message_begin(name, Thrift::MessageTypes::CALL, @seqid)
|
@@ -1,13 +1,22 @@
|
|
1
1
|
require 'thrifty_bunny'
|
2
|
-
require_relative '
|
2
|
+
require_relative 'calculator_service'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Calculator
|
5
5
|
|
6
6
|
class Handler
|
7
7
|
def say_hello(name)
|
8
8
|
puts "Saying hello to #{name}"
|
9
9
|
"Hello, #{name} from Thrift!"
|
10
10
|
end
|
11
|
+
def add(value1, value2)
|
12
|
+
value1 + value2
|
13
|
+
end
|
14
|
+
def divide(dividend, divisor)
|
15
|
+
dividend / divisor
|
16
|
+
end
|
17
|
+
|
18
|
+
def ping
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
22
|
class Server
|
@@ -15,12 +24,12 @@ module HelloThrift
|
|
15
24
|
|
16
25
|
def initialize(options={})
|
17
26
|
handler = Handler.new
|
18
|
-
processor =
|
27
|
+
processor = CalculatorService::Processor.new(handler)
|
19
28
|
@service = ThriftyBunny::RpcServer.new(processor)
|
20
29
|
end
|
21
30
|
|
22
31
|
def serve
|
23
|
-
service.serve
|
32
|
+
service.serve(log_messages: true)
|
24
33
|
end
|
25
34
|
end
|
26
35
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Siggelkow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,14 +134,12 @@ files:
|
|
134
134
|
- LICENSE.txt
|
135
135
|
- README.md
|
136
136
|
- Rakefile
|
137
|
-
- examples/bin/client.start
|
138
|
-
- examples/bin/server.start
|
139
|
-
- examples/
|
140
|
-
- examples/
|
141
|
-
- examples/
|
142
|
-
- examples/
|
143
|
-
- examples/hello_thrift/server.rb
|
144
|
-
- examples/hello_thrift/version.rb
|
137
|
+
- examples/calculator/bin/client.start
|
138
|
+
- examples/calculator/bin/server.start
|
139
|
+
- examples/calculator/calculator_service.rb
|
140
|
+
- examples/calculator/calculator_service.thrift
|
141
|
+
- examples/calculator/client.rb
|
142
|
+
- examples/calculator/server.rb
|
145
143
|
- lib/thrifty_bunny.rb
|
146
144
|
- lib/thrifty_bunny/client_transport.rb
|
147
145
|
- lib/thrifty_bunny/config.rb
|
data/examples/bin/client.start
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require_relative '../hello_thrift/client'
|
3
|
-
|
4
|
-
# transport = ThriftyBunny::ClientTransport.new
|
5
|
-
# protocol = Thrift::BinaryProtocol.new(transport)
|
6
|
-
# client = HelloThrift::Client.new(protocol)
|
7
|
-
# client = HelloThrift::Client.new
|
8
|
-
|
9
|
-
loop do
|
10
|
-
print "What is your name? "
|
11
|
-
input = gets.strip
|
12
|
-
break if input == 'quit'
|
13
|
-
puts HelloThrift::Client.new.say_hello(input)
|
14
|
-
end
|
data/examples/bin/server.start
DELETED
@@ -1,78 +0,0 @@
|
|
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
|
-
require_relative 'hello_service_types'
|
9
|
-
|
10
|
-
module HelloService
|
11
|
-
class Client
|
12
|
-
include ::Thrift::Client
|
13
|
-
|
14
|
-
def say_hello(name)
|
15
|
-
send_say_hello(name)
|
16
|
-
return recv_say_hello()
|
17
|
-
end
|
18
|
-
|
19
|
-
def send_say_hello(name)
|
20
|
-
send_message('say_hello', Say_hello_args, :name => name)
|
21
|
-
end
|
22
|
-
|
23
|
-
def recv_say_hello()
|
24
|
-
result = receive_message(Say_hello_result)
|
25
|
-
return result.success unless result.success.nil?
|
26
|
-
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'say_hello failed: unknown result')
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
class Processor
|
32
|
-
include ::Thrift::Processor
|
33
|
-
|
34
|
-
def process_say_hello(seqid, iprot, oprot)
|
35
|
-
args = read_args(iprot, Say_hello_args)
|
36
|
-
result = Say_hello_result.new()
|
37
|
-
result.success = @handler.say_hello(args.name)
|
38
|
-
write_result(result, oprot, 'say_hello', seqid)
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
# HELPER FUNCTIONS AND STRUCTURES
|
44
|
-
|
45
|
-
class Say_hello_args
|
46
|
-
include ::Thrift::Struct, ::Thrift::Struct_Union
|
47
|
-
NAME = 1
|
48
|
-
|
49
|
-
FIELDS = {
|
50
|
-
NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}
|
51
|
-
}
|
52
|
-
|
53
|
-
def struct_fields; FIELDS; end
|
54
|
-
|
55
|
-
def validate
|
56
|
-
end
|
57
|
-
|
58
|
-
::Thrift::Struct.generate_accessors self
|
59
|
-
end
|
60
|
-
|
61
|
-
class Say_hello_result
|
62
|
-
include ::Thrift::Struct, ::Thrift::Struct_Union
|
63
|
-
SUCCESS = 0
|
64
|
-
|
65
|
-
FIELDS = {
|
66
|
-
SUCCESS => {:type => ::Thrift::Types::STRING, :name => 'success'}
|
67
|
-
}
|
68
|
-
|
69
|
-
def struct_fields; FIELDS; end
|
70
|
-
|
71
|
-
def validate
|
72
|
-
end
|
73
|
-
|
74
|
-
::Thrift::Struct.generate_accessors self
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|