micro/examples/service/README.md

38 lines
695 B
Markdown
Raw Normal View History

2016-01-01 04:16:21 +03:00
# Service
2016-12-08 15:34:02 +03:00
This is an example of creating a micro service.
2016-01-01 04:16:21 +03:00
## 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.
2016-12-08 15:34:02 +03:00
Install consul
2016-01-01 04:16:21 +03:00
```shell
2016-12-08 15:34:02 +03:00
brew install consul
2016-01-01 04:16:21 +03:00
```
2016-12-08 15:34:02 +03:00
Alternative instructions - [https://www.consul.io/intro/getting-started/install.html](https://www.consul.io/intro/getting-started/install.html)
2016-01-01 04:16:21 +03:00
2016-12-08 15:34:02 +03:00
Run Consul
2016-01-01 04:16:21 +03:00
```shell
2016-12-08 15:34:02 +03:00
consul agent -dev -advertise=127.0.0.1
2016-01-01 04:16:21 +03:00
```
2016-12-08 15:34:02 +03:00
## Run the example
Run the service
2016-01-01 04:16:21 +03:00
```shell
2016-12-08 15:34:02 +03:00
go run main.go
2016-01-01 04:16:21 +03:00
```
2016-12-08 15:34:02 +03:00
Run the client
2016-01-01 04:16:21 +03:00
```shell
2016-12-08 15:34:02 +03:00
go run main.go --run_client
2016-01-01 04:16:21 +03:00
```
And that's all there is to it.