Have one server sending HTTP requests to two services, using protocol buffers as the exchanged messages.
This also serves as a proof of concept as we can achieve polymorphic types with protobuf.
v2_requests_router.rbreceives aGETrequest.- Based on this request, a message is sent to either
PDF serviceorFinalize service
- Generated with a protocol buffer
- This message has a field named
payload - This is a polymorphic field of type either
FinalizeInvoiceorGeneratePDF
- Both are listening for a
POST - Both decode the message, encoded as a protocol buffer
- Both display the message received on the console using
puts
- Protobuf. check installation guide
- Ruby (this was tested with version 2.4)
- Bundler
bundle install
- Move to protos folder
cd protos - Generate classes
protoc --ruby_out=./ *.proto- this command compiles all the files named
*.protoas ruby files, and saves the ruby files in the--ruby_outpath
- this command compiles all the files named
- open 3 consoles
ruby v2_requests_router.rbruby pdf_service.rbruby finalize_service.rb- Example of request to finalize invoices
curl -X GET 'http://localhost:4567/finalize-invoices?invoice_ids[]=124124,62322'
- Example of request to generate PDF
curl -X GET 'http://localhost:4567/generate-pdfs?invoice_ids[]=234335,222222'