A microservice architecture based on golang
-
Upload
gianfranco-reppucci -
Category
Software
-
view
1.456 -
download
7
Transcript of A microservice architecture based on golang
What is Qurami?
Select the venue you are going to
Choose from the
venues in your area, or discover all the
available venues
What is Qurami?
A venue, at a glance
Select the service of your interest, know the
exact position of the venue, get its contacts
Code facts
APIlibraries
system configurationco
ntin
uous
in
tegr
atio
n
web stuff
services
utili
ties
agent
Evolution
“The focus is moved from common technology to common interfaces, integration techniques, protocols for passing data around”
Architecture
APIs
Business Domain Models Microservices
Integration services,
Databases
3rd party services
Advantages
• “No pain” updates • Hot swappable components • Testable architecture • Really scalable • Performance statistics
Business Domain Models Microservices
APIoffice list? office list?
complete domain model
data
data presentation elaboration
• Low level software • Not accessible from apps • Single-model responsibility • Written in Golang
Business Domain Models Microservices
Business Domain Models Microservices
API
HTTP JSON-RPC server
Interface
Service core
DB conn. 3rd p. int. Helpers
ServiceName.MethodName(params)
Requirements
We needed a micro serviceto automatically deploy some applications
from a repository to a machine
Microservice structure
. ├── README.md├── interface.idl ├── main │ └── main.go ├── interfaces │ └── jsonrpc.go ├── core │ ├── deployer.go │ └── deployserver.go └── resources └── conf ├── github.ini └── server_list.ini
Microservice implementation: main
func main() { // parse some command-line parameters // such as service ID and environment ...
deployer, err := servers.NewRPCServer( new(interfaces.JSONRPCInterface), Identifier, Environment, )
if err != nil { log.Fatal(err) }
deployer.ServeJSON()
...
// wait until an exit command is given }
Microservice implementation: jsonrpc interface
func (i *JSONRPCInterface) Enqueue( r *http.Request, args *EnqueueArgs, reply *string, ) error { result, err := core.Enqueue(*args)
if err != nil { return err }
*reply = result return nil }
Microservice implementation: core excerpt...
func Enqueue(args *EnqueueArgs) QueuedCommandResult { var result QueuedCommandResult
deployer, err := NewDeployer( args.Command, args.Repository, args.AppName, args.Branch, args.DestMachine, )
if err != nil { result.Queued = false result.Message = err.Error() } else { result.Queued = true result.Message = "Started " + args.Command go deployer.SetAndExecute() }
return result }
...
Request body
{ "id": 1, "jsonrpc": "2.0", "method": "Deployer.Enqueue", "params": { "command": "DEPLOY", "repository": “my-repository", "appName": “my-application", "branch": "my-feature-branch", "destMachine": "test01" } }
Response body
{ "jsonrpc": "2.0", "result": { "queued": true, "message": "Started DEPLOY" }, "id": 1 }