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
#!/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 '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 '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 '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 'redis' | |
require 'json' | |
require './calculator' | |
calculator = Calculator.new | |
# connect to Redis | |
redis_client = Redis.connect(url: 'redis://localhost:6379') |
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' | |
# connect to Redis | |
redis_client = Redis.connect(url: 'redis://localhost:6379') | |
# request id will be used as the name of the return queue | |
request = { |
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
{ | |
"jsonrpc": "2.0", | |
"result": 6.1, | |
"id": "Ke43jnGeQsk2z9GYvFmrax" | |
} |
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
{ | |
"jsonrpc": "2.0", | |
"id": "Ke43jnGeQsk2z9GYvFmrax", | |
"method": "add", | |
"params": [1, 5.1] | |
} |
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
class Calculator | |
def add(a, b) | |
return a+b | |
end | |
def subtract(a, b) | |
return a-b | |
end |