Hubert Łępicki
@hubertlepicki
All problems in computer science can be solved by another level of indirection
...except for the problem of too many layers of indirection.
But what you really need is bigos
...but it shines with microservices
# queues-knob.yml
queues:
/queues/my_queue:
/queues/my_other_queue:
durable: false
topics:
/topics/my_topic:
# torquebox.rb
TorqueBox.configure do |cfg|
cfg.web do |web|
web.context "/ping/"
end
end
# config.ru
get '/' do
"<html><body>Hello from Torquebox</body></html>"
end
run Sinatra::Application
TorqueBox.configure do |cfg|
cfg.service MyService
end
class MyService
def initialize(args={}); end
def start; Thread.new { run }; end
def stop; @done = true; end
def run
until @done
puts "Hello #{@name}"
sleep(1)
end
end
end
# publish message in some microservice
queue = TorqueBox.fetch('/queues/foo')
queue.publish "A text message"
# and process it in other microservice
message = queue.receive
TorqueBox.configure do
...
pool :web do
min 3 # min workers
max 10 # max workers
end
end
require "vertx"
include Vertx
@server = NetServer.new.connect_handler
{ |socket|
Pump.new(socket, socket).start
}.listen(1234, 'localhost')
def vertx_stop
@server.close
end
Vertx.deploy_verticle("v1.rb", cfg[:verticle1_config])
Vertx.deploy_verticle("v2.rb", cfg[:verticle2_config], 5)
Vertx.deploy_verticle("v3.rb", cfg[:verticle3_config])
Vertx.deploy_worker_verticle("v4.rb", cfg[:verticle4_config])
Vertx.deploy_worker_verticle("v5.rb", cfg[:verticle5_config], 10)
# verticle1: send message
Vertx::EventBus.publish("test.address", 'hello world')
# verticle2: receive and reply
Vertx::EventBus.register_handler('test.address') do
|message|
puts "I received a message #{message.body}"
message.reply('This is a reply')
end
Find me on Twitter:
@hubertlepicki