2016-01-01 04:16:21 +03:00
|
|
|
# Service
|
|
|
|
|
|
|
|
This is an example of creating a micro service using the top level interface.
|
|
|
|
|
|
|
|
## Prereqs
|
|
|
|
|
|
|
|
Micro services need a discovery system so they can find each other. Micro uses consul by default but
|
|
|
|
its easily swapped out with etcd, kubernetes, or various other systems. We'll run consul for convenience.
|
|
|
|
|
|
|
|
1. Follow the install instructions - [https://www.consul.io/intro/getting-started/install.html](https://www.consul.io/intro/getting-started/install.html)
|
|
|
|
|
|
|
|
2. Run Consul
|
|
|
|
|
|
|
|
```shell
|
2016-02-08 00:30:18 +03:00
|
|
|
$ consul agent -dev -advertise=127.0.0.1
|
2016-01-01 04:16:21 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Run the example
|
|
|
|
|
|
|
|
1. Get the service
|
|
|
|
|
|
|
|
```shell
|
|
|
|
go get github.com/micro/go-micro/examples/service
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Run the server
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$GOPATH/bin/service
|
|
|
|
```
|
|
|
|
|
|
|
|
3. Run the client
|
|
|
|
|
|
|
|
```shell
|
2016-11-18 20:29:26 +03:00
|
|
|
$GOPATH/bin/service --run_client
|
2016-01-01 04:16:21 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
And that's all there is to it.
|