This is a creation in Article, where the information may have evolved or changed.
Introduction to Micro
Micro is a microservice toolkit. Its purpose are to simplify distributed systems Development.github address
Go Micro is a pluggable RPC framework for microservices. It is part of the Micro Toolkit. GitHub Address
Use Go-micro to easily build a server
Installing and running Consul,consul is a service discovery software. Micro relies on the service discovery mechanism
Installation:
Consul is the default registry/discovery for Go-micro apps. It ' s however pluggable.https://www.consul.io/intro/getting-started/install.html
Run:
consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul
Download my sample Rep
Gomicrotest
Note: There are some go dependencies that need to be git down, and then need to install PROTOBUF, specific ways to use Google
Start the Micro Web
Micro comes with a console that can view all services and interfaces
http://localhost:8082/
micro web
Start the server
Go to catalogue Server/test
go run main.go
Interface Mymicro--Testuser.getuser can select a service in Micro Web Http://localhost:8082/query after successful startup
Click Execute directly to see the output proves the service is working.
Start Client
Enter Directory Client
go run main.go
You can see the output to prove that the client connection is OK
-
Postman Test
You can open the check on the Micro Web page and then get the RPC connection under Network and copy as Curl
as follows:
Curl ' http://local Host:8082/rpc '-h ' pragma:no-cache '-h ' origin:http://localhost:8082 '-h ' accept-encoding:gzip, deflate, BR '-H ' Accept -language:zh-cn,zh;q=0.8,en;q=0.6,zh-tw;q=0.4 '-H ' user-agent:mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) applewebkit/537.36 (khtml, like Gecko) chrome/55.0.2883.95 safari/537.36 '-H ' content-type:applic Ation/json '-h ' Accept: */* '-h ' cache-control:no-cache '-h ' referer:http://localhost:8082/query '-h ' connection:keep-a Live '--data-binary ' {"Service": "Mymicro", "Method": "Testuser.getuser", "request": {}} '--compressed
Postman Use the Post method to set the following parameters for access
Address: Http://localhost:8082/rpc
Headers:content-type:application/json
body:{" Service ":" Mymicro "," Method ":" Testuser.getuser "," request ": {}}