burrow 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/README.md +9 -3
- data/lib/burrow/client.rb +29 -27
- data/lib/burrow/connection.rb +24 -22
- data/lib/burrow/request.rb +20 -18
- data/lib/burrow/response.rb +17 -15
- data/lib/burrow/server.rb +22 -20
- data/lib/burrow/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3765178f9194e1aea9658e1271fa1bf0b2eeb671
|
4
|
+
data.tar.gz: f867216f1fa303a702f400e795b5c4b1dc8235d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2fc8d0511933b824da03939bcdc473ef8974d1239123c00bcbae2cc6ded82400e47dcab32b3b874dab9d0851b604fdab3efe676a4ac2a312c43ba2f0cb8f79f
|
7
|
+
data.tar.gz: 58624ad929c1268ea0b6389717796c51830eaab92985c0fdaadf5b7530ebfc56011dfab5216ecafc6096332c0e6147e16761ade9c5380ed2562bfafa0dc7029f
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Burrow
|
2
2
|
|
3
|
-
This gem builds on top of the
|
4
|
-
|
3
|
+
This gem builds on top of the [bunny gem](https://github.com/ruby-amqp/bunny) for messaging with RabbitMQ and aims to remove most of the boilerplate code.
|
4
|
+
|
5
|
+
The [Micromessaging: Connecting Heroku Microservices w/Redis and RabbitMQ](http://blog.carbonfive.com/2014/04/28/micromessaging-connecting-heroku-microservices-wredis-and-rabbitmq/) article was the basis for the vast majority of the code here.
|
5
6
|
|
6
7
|
**This gem is what it is, do not expect amazing support here!**
|
7
8
|
|
@@ -39,9 +40,14 @@ client = Burrow::Client.new('my_queue')
|
|
39
40
|
json = client.publish('my_method', first_param: 'one', second_param: 'two')
|
40
41
|
```
|
41
42
|
|
43
|
+
## Todo
|
44
|
+
|
45
|
+
- Document the configuration options for `bunny`
|
46
|
+
- Figure out how to handle errors
|
47
|
+
|
42
48
|
## Contributing
|
43
49
|
|
44
|
-
1. Fork it ( https://github.com/
|
50
|
+
1. Fork it ( https://github.com/tigrish/burrow/fork )
|
45
51
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
52
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
53
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/burrow/client.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Burrow
|
2
|
+
class Client
|
3
|
+
attr_reader :connection, :request
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(queue)
|
6
|
+
@connection = Burrow::Connection.new(queue)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def publish(method, params={})
|
10
|
+
@request = Burrow::Request.new(method, params)
|
11
|
+
publish_request
|
12
|
+
subscribe_response
|
13
|
+
end
|
13
14
|
|
14
|
-
protected
|
15
|
+
protected
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
def publish_request
|
18
|
+
connection.exchange.publish(
|
19
|
+
request.json, {
|
20
|
+
correlation_id: request.id,
|
21
|
+
reply_to: connection.return_queue.name,
|
22
|
+
routing_key: connection.queue.name
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
def subscribe_response
|
28
|
+
response = nil
|
29
|
+
connection.return_queue.subscribe(block: true) do |delivery_info, properties, payload|
|
30
|
+
if properties[:correlation_id] == request.id
|
31
|
+
response = payload
|
32
|
+
delivery_info.consumer.cancel
|
33
|
+
end
|
32
34
|
end
|
35
|
+
JSON.parse(response)
|
33
36
|
end
|
34
|
-
JSON.parse(response)
|
35
37
|
end
|
36
38
|
end
|
data/lib/burrow/connection.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Burrow
|
2
|
+
class Connection
|
3
|
+
attr_reader :queue_name
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(queue_name)
|
6
|
+
@queue_name = queue_name
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def connection
|
10
|
+
@connection ||= begin
|
11
|
+
c = Bunny.new
|
12
|
+
c.start
|
13
|
+
c
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def channel
|
18
|
+
@channel ||= connection.create_channel
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def queue
|
22
|
+
@queue ||= channel.queue(queue_name, auto_delete: false)
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def exchange
|
26
|
+
@exchange ||= channel.default_exchange
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
def return_queue
|
30
|
+
@return_queue ||= channel.queue('', exclusive: true)
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/burrow/request.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Burrow
|
2
|
+
class Request
|
3
|
+
attr_reader :method, :params
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(method, params={})
|
6
|
+
@method = method
|
7
|
+
@params = params
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def id
|
11
|
+
@id ||= SecureRandom.hex
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def attributes
|
15
|
+
{ jsonrpc: '2.0',
|
16
|
+
id: id,
|
17
|
+
method: method,
|
18
|
+
params: params
|
19
|
+
}
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def json
|
23
|
+
JSON.generate(attributes)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
data/lib/burrow/response.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Burrow
|
2
|
+
class Response
|
3
|
+
attr_reader :id, :params
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(id, params)
|
6
|
+
@id = id
|
7
|
+
@params = params
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def json
|
11
|
+
JSON.generate(attributes)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def attributes
|
15
|
+
{
|
16
|
+
id: id,
|
17
|
+
result: params,
|
18
|
+
jsonrpc: '2.0'
|
19
|
+
}
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
data/lib/burrow/server.rb
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Burrow
|
2
|
+
class Server
|
3
|
+
attr_reader :connection
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(queue)
|
6
|
+
@connection = Burrow::Connection.new(queue)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
def subscribe
|
10
|
+
connection.queue.subscribe(block: true) do |delivery_info, properties, payload|
|
11
|
+
request = JSON.parse(payload)
|
12
|
+
result = yield [request['method'], request['params']]
|
13
|
+
response = Burrow::Response.new(request['id'], result)
|
14
|
+
publish_response(response, properties)
|
15
|
+
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
17
|
-
protected
|
18
|
+
protected
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
def publish_response(response, properties)
|
21
|
+
connection.exchange.publish(
|
22
|
+
response.json, {
|
23
|
+
routing_key: properties.reply_to,
|
24
|
+
correlation_id: properties.correlation_id
|
25
|
+
}
|
26
|
+
)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/burrow/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: burrow
|
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
|
- Christopher Dell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|