cotton-tail 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Gemfile.lock +1 -1
- data/examples/app.rb +9 -17
- data/examples/app_with_middleware.rb +12 -2
- data/lib/cotton_tail/app.rb +6 -3
- data/lib/cotton_tail/configuration.rb +3 -3
- data/lib/cotton_tail/middleware/router.rb +11 -14
- data/lib/cotton_tail/middleware.rb +4 -2
- data/lib/cotton_tail/queue/bunny.rb +4 -6
- data/lib/cotton_tail/queue/reader.rb +6 -2
- data/lib/cotton_tail/version.rb +1 -1
- data/lib/cotton_tail.rb +15 -4
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e850fbee254829b5680d9ef8b653f7112d839340070c63133e1615d02a2717d8
|
4
|
+
data.tar.gz: bcf0010028eb6b98a227764f951b5a9b2d50a0b1cc0beface95838295dfbee48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fff4b3fec0934022cd1255e95557f9fd7e0be9011a91affcb30be960b8e5ff84c149f83ab7bc047a13909999292f57f51b32b31271c888820176e0f22ea854a
|
7
|
+
data.tar.gz: f5a658bbb3f3473fc9aac6331f76c435aa0cc297a5be6dbe783972ae895761b54eac3c5577b2d23ab6f7e4d46c6bdb62baf6fd8a57113cbf29f9022ad32420aa
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/examples/app.rb
CHANGED
@@ -20,30 +20,22 @@ app.routes.draw do
|
|
20
20
|
puts 'Goodbye cruel world!'
|
21
21
|
end
|
22
22
|
|
23
|
-
handle 'inspect.message' do |env,
|
23
|
+
handle 'inspect.message' do |env, request, response|
|
24
24
|
puts env: env
|
25
|
-
puts
|
26
|
-
puts
|
27
|
-
puts properties: properties
|
28
|
-
puts payload: payload
|
25
|
+
puts request: request
|
26
|
+
puts response: response
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
30
|
queue 'require_ack_queue', exclusive: true, manual_ack: true do
|
33
|
-
handle 'get.acked' do |_env,
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
ch = delivery_info[:channel]
|
38
|
-
ch.ack(delivery_tag)
|
31
|
+
handle 'get.acked' do |_env, request, _response|
|
32
|
+
puts "acking with #{request.delivery_tag}"
|
33
|
+
request.channel.ack(request.delivery_tag)
|
39
34
|
end
|
40
35
|
|
41
|
-
handle 'get.nacked' do |_env,
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
ch = delivery_info[:channel]
|
46
|
-
ch.nack(delivery_tag)
|
36
|
+
handle 'get.nacked' do |_env, request, _response|
|
37
|
+
puts "nacking with #{request.delivery_tag}"
|
38
|
+
request.channel.nack(request.delivery_tag)
|
47
39
|
end
|
48
40
|
end
|
49
41
|
end
|
@@ -6,10 +6,20 @@ require 'cotton_tail'
|
|
6
6
|
|
7
7
|
app = CottonTail::App.new
|
8
8
|
|
9
|
-
|
9
|
+
upcase = lambda { |(env, req, res)|
|
10
|
+
[env, req, CottonTail::Response.new(res.body.upcase)]
|
11
|
+
}
|
12
|
+
|
13
|
+
print = lambda { |(env, req, res)|
|
14
|
+
puts res.body
|
15
|
+
[env, req, res]
|
16
|
+
}
|
17
|
+
|
18
|
+
app.config.middleware do |d|
|
10
19
|
# This is added to the end of the middleware stack
|
11
20
|
# 'message' is the return value of the handlers defined below
|
12
|
-
d.use
|
21
|
+
d.use upcase
|
22
|
+
d.use print
|
13
23
|
end
|
14
24
|
|
15
25
|
app.routes.draw do
|
data/lib/cotton_tail/app.rb
CHANGED
@@ -3,15 +3,18 @@
|
|
3
3
|
module CottonTail
|
4
4
|
# App is the main class for a CottonTail server
|
5
5
|
class App
|
6
|
-
attr_reader :env
|
6
|
+
attr_reader :env
|
7
7
|
|
8
|
-
def initialize(queue_strategy: Queue::Bunny, env: {}, connection: Bunny.new
|
8
|
+
def initialize(queue_strategy: Queue::Bunny, env: {}, connection: Bunny.new)
|
9
9
|
@dependencies = { queue_strategy: queue_strategy, connection: connection }
|
10
10
|
@env = env
|
11
|
-
@config = config
|
12
11
|
@connection = connection.start
|
13
12
|
end
|
14
13
|
|
14
|
+
def config
|
15
|
+
@config ||= Configuration.new(middleware: Middleware.default_stack(self))
|
16
|
+
end
|
17
|
+
|
15
18
|
def queues
|
16
19
|
routes.queues
|
17
20
|
end
|
@@ -7,9 +7,9 @@ module CottonTail
|
|
7
7
|
class Configuration
|
8
8
|
attr_reader :connection_args
|
9
9
|
|
10
|
-
def initialize
|
10
|
+
def initialize(middleware: nil)
|
11
11
|
@connection_args = nil
|
12
|
-
@middleware =
|
12
|
+
@middleware = middleware
|
13
13
|
@user_configs = {}
|
14
14
|
end
|
15
15
|
|
@@ -29,7 +29,7 @@ module CottonTail
|
|
29
29
|
return @middleware unless block_given?
|
30
30
|
|
31
31
|
@middleware = ::Middleware::Builder.new do |b|
|
32
|
-
b.use @middleware
|
32
|
+
b.use @middleware if @middleware
|
33
33
|
yield b
|
34
34
|
end
|
35
35
|
end
|
@@ -4,29 +4,26 @@ module CottonTail
|
|
4
4
|
module Middleware
|
5
5
|
# Router Middleware
|
6
6
|
class Router
|
7
|
-
|
7
|
+
attr_reader :handlers
|
8
|
+
|
9
|
+
def initialize(app, handlers:)
|
8
10
|
@app = app
|
11
|
+
@handlers = handlers
|
9
12
|
end
|
10
13
|
|
11
|
-
def call(
|
12
|
-
|
13
|
-
|
14
|
-
request.unshift message.app.env
|
15
|
-
@app.call handler(message.app, message.routing_key).call(request)
|
14
|
+
def call(message)
|
15
|
+
env, req, = message
|
16
|
+
@app.call [env, req, response(req.routing_key, message)]
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
|
20
|
-
def handler(
|
21
|
-
handlers
|
22
|
-
end
|
23
|
-
|
24
|
-
def parse(msg)
|
25
|
-
Message.new(*msg)
|
21
|
+
def handler(route)
|
22
|
+
handlers.fetch(route) { raise UndefinedRouteError }
|
26
23
|
end
|
27
24
|
|
28
|
-
def
|
29
|
-
|
25
|
+
def response(routing_key, message)
|
26
|
+
CottonTail::Response.new handler(routing_key).call(message)
|
30
27
|
end
|
31
28
|
end
|
32
29
|
end
|
@@ -8,8 +8,10 @@ module CottonTail
|
|
8
8
|
module Middleware
|
9
9
|
autoload :Router, 'cotton_tail/middleware/router'
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
def self.default_stack(app)
|
12
|
+
::Middleware::Builder.new do |b|
|
13
|
+
b.use Router, handlers: app.routes.handlers
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -24,15 +24,13 @@ module CottonTail
|
|
24
24
|
watch_source manual_ack
|
25
25
|
end
|
26
26
|
|
27
|
-
def push(
|
28
|
-
routing_key
|
29
|
-
|
30
|
-
exchange.publish message, routing_key: routing_key
|
27
|
+
def push(request)
|
28
|
+
bind request.routing_key
|
29
|
+
exchange.publish request.payload, routing_key: request.routing_key
|
31
30
|
end
|
32
31
|
|
33
32
|
def pop
|
34
|
-
|
35
|
-
[delivery_info[:routing_key], delivery_info, *tail]
|
33
|
+
Request.new(*super)
|
36
34
|
end
|
37
35
|
|
38
36
|
def bind(routing_key)
|
@@ -28,13 +28,17 @@ module CottonTail
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def call_next
|
31
|
-
|
32
|
-
middleware.call([
|
31
|
+
request = fiber.resume
|
32
|
+
middleware.call([env, request, Response.new]) if request
|
33
33
|
end
|
34
34
|
|
35
35
|
def middleware
|
36
36
|
@app.config.middleware
|
37
37
|
end
|
38
|
+
|
39
|
+
def env
|
40
|
+
@app.env
|
41
|
+
end
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
data/lib/cotton_tail/version.rb
CHANGED
data/lib/cotton_tail.rb
CHANGED
@@ -12,10 +12,21 @@ module CottonTail
|
|
12
12
|
autoload :Router, 'cotton_tail/router'
|
13
13
|
autoload :Version, 'cotton_tail/version'
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
Request = Struct.new(:delivery_info, :properties, :payload) do
|
16
|
+
def routing_key
|
17
|
+
delivery_info[:routing_key]
|
18
|
+
end
|
19
|
+
|
20
|
+
def delivery_tag
|
21
|
+
delivery_info[:delivery_tag]
|
22
|
+
end
|
23
|
+
|
24
|
+
def channel
|
25
|
+
delivery_info[:channel]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Response = Struct.new(:body)
|
19
30
|
|
20
31
|
class UndefinedRouteError < StandardError
|
21
32
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotton-tail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Brennan
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
fXe/xr/Sc+2wCjHPVE2J+auN5hk3KCp1I4s2fKqyLIwyhTEF3shuYfCpC8rt/YdN
|
31
31
|
cy9/lg5LCI3OvakzxL4Xt1Sq4h/xJZ06ydTVJ1wxfk6BXHrg
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2018-11-
|
33
|
+
date: 2018-11-30 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: bunny
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
L���w�T�>+�Xd��g��S�c�Gܤ̧��W�15��/��t���]DkZ�O�f��
|
2
|
+
�=���`�XD���`�~Z-����x��b�7C��`n0z�]�Q�'��=`V>B�i���x��_��q��>$*���Y�"m
|