burrow 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16010405f0c88acaf6ad8debb6f7b8ef41c78bbd
4
- data.tar.gz: 30cc5337ac3e94ed1522323c74d8c2c8e0eb98b2
3
+ metadata.gz: 3765178f9194e1aea9658e1271fa1bf0b2eeb671
4
+ data.tar.gz: f867216f1fa303a702f400e795b5c4b1dc8235d6
5
5
  SHA512:
6
- metadata.gz: 7f2dee63036cce37584b02b871a43567c9e39dac55e4f76ce9ffbf1148d755a3c9f47a2e5c3591a0022f4d6242b5f996419e26249f790c142a40cd1d31ce7f0c
7
- data.tar.gz: 0163ca4d96c1d5969aa5619796a1c7f7ed52bad9cccfd31244f2645ce29b24b446c39aeea611c65eebd5ef05c9af5d7e4d0ec6215f0c7aee805ac50e4481e102
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 `bunny` gem and aims to remove as much of
4
- the boilerplate code as possible.
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/[my-github-username]/burrow/fork )
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`)
@@ -1,36 +1,38 @@
1
- class Burrow::Client
2
- attr_reader :connection, :request
1
+ module Burrow
2
+ class Client
3
+ attr_reader :connection, :request
3
4
 
4
- def initialize(queue)
5
- @connection = Burrow::Connection.new(queue)
6
- end
5
+ def initialize(queue)
6
+ @connection = Burrow::Connection.new(queue)
7
+ end
7
8
 
8
- def publish(method, params={})
9
- @request = Burrow::Request.new(method, params)
10
- publish_request
11
- subscribe_response
12
- end
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
- def publish_request
17
- connection.exchange.publish(
18
- request.json, {
19
- correlation_id: request.id,
20
- reply_to: connection.return_queue.name,
21
- routing_key: connection.queue.name
22
- }
23
- )
24
- end
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
- def subscribe_response
27
- response = nil
28
- connection.return_queue.subscribe(block: true) do |delivery_info, properties, payload|
29
- if properties[:correlation_id] == request.id
30
- response = payload
31
- delivery_info.consumer.cancel
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
@@ -1,31 +1,33 @@
1
- class Burrow::Connection
2
- attr_reader :queue_name
1
+ module Burrow
2
+ class Connection
3
+ attr_reader :queue_name
3
4
 
4
- def initialize(queue_name)
5
- @queue_name = queue_name
6
- end
5
+ def initialize(queue_name)
6
+ @queue_name = queue_name
7
+ end
7
8
 
8
- def connection
9
- @connection ||= begin
10
- c = Bunny.new
11
- c.start
12
- c
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
- def channel
17
- @channel ||= connection.create_channel
18
- end
17
+ def channel
18
+ @channel ||= connection.create_channel
19
+ end
19
20
 
20
- def queue
21
- @queue ||= channel.queue(queue_name, auto_delete: false)
22
- end
21
+ def queue
22
+ @queue ||= channel.queue(queue_name, auto_delete: false)
23
+ end
23
24
 
24
- def exchange
25
- @exchange ||= channel.default_exchange
26
- end
25
+ def exchange
26
+ @exchange ||= channel.default_exchange
27
+ end
27
28
 
28
- def return_queue
29
- @return_queue ||= channel.queue('', exclusive: true)
29
+ def return_queue
30
+ @return_queue ||= channel.queue('', exclusive: true)
31
+ end
30
32
  end
31
33
  end
@@ -1,24 +1,26 @@
1
- class Burrow::Request
2
- attr_reader :method, :params
1
+ module Burrow
2
+ class Request
3
+ attr_reader :method, :params
3
4
 
4
- def initialize(method, params={})
5
- @method = method
6
- @params = params
7
- end
5
+ def initialize(method, params={})
6
+ @method = method
7
+ @params = params
8
+ end
8
9
 
9
- def id
10
- @id ||= SecureRandom.hex
11
- end
10
+ def id
11
+ @id ||= SecureRandom.hex
12
+ end
12
13
 
13
- def attributes
14
- { jsonrpc: '2.0',
15
- id: id,
16
- method: method,
17
- params: params
18
- }
19
- end
14
+ def attributes
15
+ { jsonrpc: '2.0',
16
+ id: id,
17
+ method: method,
18
+ params: params
19
+ }
20
+ end
20
21
 
21
- def json
22
- JSON.generate(attributes)
22
+ def json
23
+ JSON.generate(attributes)
24
+ end
23
25
  end
24
26
  end
@@ -1,20 +1,22 @@
1
- class Burrow::Response
2
- attr_reader :id, :params
1
+ module Burrow
2
+ class Response
3
+ attr_reader :id, :params
3
4
 
4
- def initialize(id, params)
5
- @id = id
6
- @params = params
7
- end
5
+ def initialize(id, params)
6
+ @id = id
7
+ @params = params
8
+ end
8
9
 
9
- def json
10
- JSON.generate(attributes)
11
- end
10
+ def json
11
+ JSON.generate(attributes)
12
+ end
12
13
 
13
- def attributes
14
- {
15
- id: id,
16
- result: params,
17
- jsonrpc: '2.0'
18
- }
14
+ def attributes
15
+ {
16
+ id: id,
17
+ result: params,
18
+ jsonrpc: '2.0'
19
+ }
20
+ end
19
21
  end
20
22
  end
@@ -1,27 +1,29 @@
1
- class Burrow::Server
2
- attr_reader :connection
1
+ module Burrow
2
+ class Server
3
+ attr_reader :connection
3
4
 
4
- def initialize(queue)
5
- @connection = Burrow::Connection.new(queue)
6
- end
5
+ def initialize(queue)
6
+ @connection = Burrow::Connection.new(queue)
7
+ end
7
8
 
8
- def subscribe
9
- connection.queue.subscribe(block: true) do |delivery_info, properties, payload|
10
- request = JSON.parse(payload)
11
- result = yield [request['method'], request['params']]
12
- response = Burrow::Response.new(request['id'], result)
13
- publish_response(response, properties)
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
- def publish_response(response, properties)
20
- connection.exchange.publish(
21
- response.json, {
22
- routing_key: properties.reply_to,
23
- correlation_id: properties.correlation_id
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
@@ -1,3 +1,3 @@
1
1
  module Burrow
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-03 00:00:00.000000000 Z
11
+ date: 2014-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny