rodent 0.0.3 → 0.0.4

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: 242d93035344222686b1756ce592417080f9631b
4
- data.tar.gz: 40812bd7ee47172f5f3b8785e3f6ed42510fef9c
3
+ metadata.gz: 9c5f5acd62d35708b4c479376ee213fce72db021
4
+ data.tar.gz: f5a167799d4f338b0f710bc9b37e0938b0c2218a
5
5
  SHA512:
6
- metadata.gz: f86582528021e17f9754a258c20c74cdb1a55772b29f1d1d07f53de080c94c91698e25431f6d5f8dc5f3bde7508021adbac595f10dcf1445f4162f04e2af9fed
7
- data.tar.gz: 1b50d4dfa8bb5ba18a5553440806f4388789fa3417c229bcd05c0a2b4e938b125b86a84950e6053fec89d6a05af163160ef17f27bf9d7bf7f6c5d2bd570c1682
6
+ metadata.gz: 1835d65838471df32ea85c56ed15f6cc0fe0bfa2a5ae9aa466179fb829e20f0f33a06faf4b6a64e5be7c7480e305b4db492e4974578978d7e346ceb5dcc67d1f
7
+ data.tar.gz: dd91fa08ee77cc2196cb8cac75c4dfaa1534e6b8477f273fee6490577dc0b94e33bc3a4f4c3a091fc671da6eda09d34167f7c82351979acbef896d77e0abe724
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  Gemfile.lock
2
2
  log/*.log
3
3
  *.gem
4
+ .yardoc/
5
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ services:
6
+ - rabbitmq
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --main README.md
2
+ --no-private
3
+ --markup-provider=redcarpet
4
+ --markup=markdown
data/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # Rodent
2
+
3
+ [![Code Climate](https://codeclimate.com/github/kkdoo/rodent.png)](https://codeclimate.com/github/kkdoo/rodent) [![Build Status](https://travis-ci.org/kkdoo/rodent.png?branch=master)](https://travis-ci.org/kkdoo/rodent) [![Dependency Status](https://gemnasium.com/kkdoo/rodent.png)](https://gemnasium.com/kkdoo/rodent)
4
+
5
+ Rodent is an open source asynchronous framework for Micro Service Architecture (MSA). It is a lightweight and designed to easily develop APIs. Main goals is scaling, simplicity and perfomance.
6
+
7
+ The framework uses [Goliath](https://github.com/postrank-labs/goliath) as HTTP proxy and [AMQP](https://github.com/ruby-amqp/amqp) protocol to connect MSA for handling requests. Micro Services can be run separately and multiple times for scaling, hot-reloading or language independence. All requests are load balanced with same MSA.
8
+
9
+ You can learn more about MSA in great [article](http://yobriefca.se/blog/2013/04/29/micro-service-architecture/) by James Hughes.
10
+
11
+ ## Installation & Prerequisites
12
+
13
+ Rodent is available as a gem, to install it just install the gem
14
+
15
+ ```bash
16
+ $> gem install rodent
17
+ ```
18
+
19
+ If you're using Bundler, add the gem to Gemfile
20
+
21
+ ```ruby
22
+ gem 'rodent'
23
+ ```
24
+
25
+ ## Getting Started: Hello World
26
+
27
+ Proxy server for sending HTTP requests into Micro Service (based on [Grape](https://github.com/intridea/grape))
28
+
29
+ ```ruby
30
+ # proxy.rb
31
+
32
+ require 'rodent'
33
+ require 'grape'
34
+
35
+ class CustomersProxy < Grape::API
36
+ version 'v1', using: :path
37
+ format :json
38
+ default_format :json
39
+
40
+ resource :customers do
41
+ params do
42
+ requires :name, type: String
43
+ requires :email, type: String
44
+ end
45
+ post '/' do
46
+ header 'Rodent-Proxy', 'customers.create'
47
+
48
+ {name: params[:name], email: params[:email]}
49
+ end
50
+ end
51
+ end
52
+
53
+ class ProxyApp < Goliath::API
54
+ plugin Rodent::Goliath::Plugin
55
+ use Rodent::Goliath::Middleware
56
+
57
+ def response(env)
58
+ CustomersProxy.call(env)
59
+ end
60
+ end
61
+ ```
62
+
63
+ Micro Service for handling requests
64
+
65
+ ```ruby
66
+ # customers.rb
67
+
68
+ require 'rodent'
69
+
70
+ class Customer
71
+ attr_accessor :name, :email
72
+
73
+ def initialize(options)
74
+ @name = options['name']
75
+ @email = options['email']
76
+ end
77
+
78
+ def as_json
79
+ {recipient: [name, ' <', email, '>'].join}
80
+ end
81
+ end
82
+
83
+ class CustomersAPI < Rodent::Base
84
+ listen 'customers.create' do
85
+ self.status = 201
86
+
87
+ @customer = Customer.new(params)
88
+ @customer.as_json
89
+ end
90
+ end
91
+
92
+ class CustomersServer < Rodent::Server
93
+ configure do
94
+ set :connection, 'amqp://guest:guest@localhost'
95
+ end
96
+
97
+ run do
98
+ Signal.trap('INT') { Rodent::Server.stop }
99
+
100
+ [CustomersAPI]
101
+ end
102
+ end
103
+ ```
104
+
105
+ Run proxy server
106
+
107
+ ```bash
108
+ $> ruby proxy.rb -v -s -e development -p 3000
109
+ ```
110
+
111
+ Run micro service
112
+
113
+ ```bash
114
+ $> ruby customers.rb
115
+ ```
116
+
117
+ Then you can test it
118
+ ```bash
119
+ $> curl -X POST localhost:3000/v1/customers -d "name=Bob" -d "email=bob@example.com"
120
+ ```
121
+
122
+ ## Performance
123
+
124
+ My results is below
125
+
126
+ ```bash
127
+ Server Software: Goliath
128
+ Server Hostname: localhost
129
+ Server Port: 3000
130
+
131
+ Document Path: /v1/customers
132
+ Document Length: 2 bytes
133
+
134
+ Concurrency Level: 50
135
+ Time taken for tests: 2.450 seconds
136
+ Complete requests: 1000
137
+ Failed requests: 0
138
+ Write errors: 0
139
+ Total transferred: 126000 bytes
140
+ HTML transferred: 2000 bytes
141
+ Requests per second: 408.18 [#/sec] (mean)
142
+ Time per request: 122.495 [ms] (mean)
143
+ Time per request: 2.450 [ms] (mean, across all concurrent requests)
144
+ Transfer rate: 50.23 [Kbytes/sec] received
145
+
146
+ Connection Times (ms)
147
+ min mean[+/-sd] median max
148
+ Connect: 0 2 1.0 2 5
149
+ Processing: 51 118 40.5 116 233
150
+ Waiting: 45 116 41.0 115 232
151
+ Total: 51 120 40.7 117 235
152
+ ```
153
+
154
+ ## License & Acknowledgments
155
+
156
+ Rodent is distributed under the MIT license, for full details please see the LICENSE file.
@@ -39,23 +39,26 @@ module Rodent
39
39
  replies_queue = channel.queue(message_id, exclusive: true, auto_delete: true)
40
40
 
41
41
  consumer = AMQP::Consumer.new(channel, replies_queue)
42
-
43
- consumer.consume do
44
- consumer.on_delivery do |metadata, payload|
45
- response = MultiJson.load(payload)
46
- response['headers']['Content-Length'] = response['body'].length.to_s
47
- response['headers']['Content-Type'] = 'application/json'
48
- async_callback.call([response['status'], headers.merge(response['headers']), response['body']])
49
- metadata.ack
50
- consumer.cancel
51
- end
52
- end
42
+ bind_consumer(consumer, async_callback, headers)
53
43
 
54
44
  channel.direct('rodent.requests').publish(body, routing_key: type, message_id: message_id, reply_to: replies_queue.name)
55
45
  end
56
46
 
57
47
  ::Goliath::Connection::AsyncResponse
58
48
  end
49
+
50
+ def bind_consumer(consumer, async_callback, headers)
51
+ consumer.consume do
52
+ consumer.on_delivery do |metadata, payload|
53
+ response = MultiJson.load(payload)
54
+ response['headers']['Content-Length'] = response['body'].length.to_s
55
+ response['headers']['Content-Type'] = 'application/json'
56
+ async_callback.call([response['status'], headers.merge(response['headers']), response['body']])
57
+ metadata.ack
58
+ consumer.cancel
59
+ end
60
+ end
61
+ end
59
62
  end
60
63
  end
61
64
  end
@@ -1,3 +1,3 @@
1
1
  module Rodent
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/rodent.gemspec CHANGED
@@ -28,6 +28,8 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'em-http-request'
29
29
  s.add_development_dependency 'rack-test'
30
30
  s.add_development_dependency 'evented-spec'
31
+ s.add_development_dependency 'redcarpet'
32
+ s.add_development_dependency 'yard'
31
33
 
32
34
  s.files = `git ls-files`.split("\n")
33
35
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -29,7 +29,9 @@ describe Rodent::Base do
29
29
  end
30
30
  end
31
31
 
32
- CustomersAPI.bind
32
+ done do
33
+ CustomersAPI.bind
34
+ end
33
35
  end
34
36
 
35
37
  after(:all) do
@@ -40,9 +42,10 @@ describe Rodent::Base do
40
42
  it 'should return right response' do
41
43
  params = {name: 'Bob Marley', email: 'bob@example.com'}
42
44
 
43
- @channel.direct('rodent.requests').publish(MultiJson.dump(params), routing_key: 'customers.create', message_id: @message_id, reply_to: @replies_queue.name)
45
+ @channel.direct('rodent.requests').publish MultiJson.dump(params), routing_key: 'customers.create',
46
+ message_id: @message_id, reply_to: @replies_queue.name
44
47
 
45
- done(0.5) do
48
+ done(2.0) do
46
49
  @response.should_not be_nil
47
50
  @response['status'].should == 201
48
51
  @response['headers'].should == {'API-Version' => 'v1'}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Maschenko
@@ -150,6 +150,34 @@ dependencies:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: redcarpet
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  description: Framework for micro services
154
182
  email:
155
183
  - artem.maschenko@gmail.com
@@ -158,8 +186,12 @@ extensions: []
158
186
  extra_rdoc_files: []
159
187
  files:
160
188
  - .gitignore
189
+ - .rspec
190
+ - .travis.yml
191
+ - .yardopts
161
192
  - Gemfile
162
193
  - LICENSE
194
+ - README.md
163
195
  - Rakefile
164
196
  - examples/customers.rb
165
197
  - examples/proxy.rb