This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bunny' | |
require 'json' | |
require './calculator' | |
calculator = Calculator.new | |
# connect to RabbitMQ | |
conn = Bunny.new | |
conn.start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bunny' | |
require 'securerandom' | |
require 'json' | |
conn = Bunny.new | |
conn.start | |
ch = conn.create_channel | |
q = ch.queue('calc', auto_delete: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'sinatra' | |
require './calculator' | |
calculator = Calculator.new | |
post '/calc' do | |
req = JSON.parse(request.body.read) | |
# call a method on the calculator instance, passing along params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'securerandom' | |
require 'json' | |
uri = URI('http://localhost:4567/calc') | |
req = Net::HTTP::Post.new(uri.path) | |
req.body = { | |
'id' => SecureRandom.hex, | |
'jsonrpc' => '2.0', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'redis' | |
require 'securerandom' | |
require 'json' | |
class RedisRpcClient | |
def initialize(redis_url, list_name) | |
@redis_client = Redis.connect(url: redis_url) | |
@list_name = list_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rehearsal -------------------------------------------- | |
RabbitMQ 0.980000 0.570000 1.550000 ( 1.602346) | |
Redis 0.280000 0.040000 0.320000 ( 0.419955) | |
HTTP 0.500000 0.200000 0.700000 ( 2.436720) | |
----------------------------------- total: 2.570000sec | |
user system total real | |
RabbitMQ 0.980000 0.580000 1.560000 ( 1.604432) | |
Redis 0.270000 0.040000 0.310000 ( 0.416424) | |
HTTP 0.490000 0.190000 0.680000 ( 6.691767) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'securerandom' | |
require 'json' | |
require 'benchmark' | |
require 'redis' | |
require 'bunny' | |
require 'pry' | |
uri = URI('http://localhost:4567/calc') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Contact Service API Reference | |
/api/v1/contacts.json | |
## Reading | |
GET /contacts.json HTTP/1.1 | |
Host: example.com | |
### Fields |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST \ | |
-H "Content-Type: application/json" \ | |
-d '{"first_name": "Erin", "last_name": "S-H", "age": 32, "importance_level": 100, "alias": "lzr"}' \ | |
http://example.com/api/v1/contacts.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST \ | |
-H "Content-Type: application/json" \ | |
-d '{"full_name": "Erin S-H", "age": 32, "importance_level": 100, "alias": "laser"}' \ | |
http://example.com/api/v1/contacts.json |