Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harlow/go-micro-services
HTTP up front, Protobufs in the rear
https://github.com/harlow/go-micro-services
consul go golang grpc jaeger microservice protobuf
Last synced: 1 day ago
JSON representation
HTTP up front, Protobufs in the rear
- Host: GitHub
- URL: https://github.com/harlow/go-micro-services
- Owner: harlow
- License: mit
- Created: 2015-01-12T06:31:38.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T00:30:52.000Z (about 1 year ago)
- Last Synced: 2025-01-17T19:19:48.220Z (8 days ago)
- Topics: consul, go, golang, grpc, jaeger, microservice, protobuf
- Language: Go
- Homepage:
- Size: 13.8 MB
- Stars: 1,086
- Watchers: 42
- Forks: 166
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-repositories - go-micro-services
- awesome-grpc - go-micro-services - An demonstration of Golang micro-services that expose a HTTP/JSON frontend and then leverages gRPC for inter-service communication (Resources / Examples)
- awesome-list-microservice - go-micro-services
README
# Golang Microservices Example
A demonstration of Golang micro-services that expose a HTTP/JSON frontend and then
leverages [gRPC][1] for inter-service communication.* Services written in Golang
* gRPC for inter-service communication
* Jaeger for request tracingThe example application plots Hotel locations on a Google map:
The web page makes an HTTP request to the API Endpoint which in turn spawns a number of RPC requests to the backend services.
Data for each of the services is stored in JSON flat files under the `data/` directory. In reality each of the services could choose their own specialty datastore. The Geo service for example could use PostGis or any other database specializing in geospacial queries.
## Installation
### Setup
Docker is required for running the services https://docs.docker.com/engine/installation.
Protobuf v3 are required:
$ brew install protobuf
Install the protoc-gen libraries:
$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
Clone the repository:
$ git clone [email protected]:harlow/go-micro-services.git
### Run
To make the demo as straigforward as possible; [Docker Compose](https://docs.docker.com/compose/) is used to run all the services at once (In a production environment each of the services would be run (and scaled) independently).
$ make run
Vist the web page in a browser:
[http://localhost:5000/](http://localhost:5000/)
cURL the API endpoint and receive GeoJSON response:
$ curl "http://localhost:5000/hotels?inDate=2015-04-09&outDate=2015-04-10"
The JSON response:
```json
{
"type": "FeatureCollection",
"features": [{
"id": "5",
"type": "Feature",
"properties": {
"name": "Phoenix Hotel",
"phone_number": "(415) 776-1380"
},
"geometry": {
"type": "Point",
"coordinates": [-122.4181, 37.7831]
}
}, {
"id": "3",
"type": "Feature",
"properties": {
"name": "Hotel Zetta",
"phone_number": "(415) 543-8555"
},
"geometry": {
"type": "Point",
"coordinates": [-122.4071, 37.7834]
}
}]
}
```## Request Tracing
The [Jaeger Tracing](https://github.com/jaegertracing/jaeger) project is used for tracing inter-service requests. The `tracing` package is used initialize a new service tracer:
```go
tracer, err := tracing.Init("serviceName", jaegeraddr)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
```View dashboard: http://localhost:16686/search
### Protobufs
If changes are made to the Protocol Buffer files use the Makefile to regenerate:
$ make proto
### Bindata
The example app data is stored in flat files in the `/data` directory. When any of
the data files are manually editied the bindata must be regenerated.Install the go-bindata libraries:
$ go get -u github.com/go-bindata/go-bindata/...
If changes are made to any of the raw JSON data files use the Makefile to regenerate:
$ make data
## Credits
Thanks to all the [contributors][6]. This codebase was heavily inspired by the following talks and repositories:
* [Scaling microservices in Go][3]
* [gRPC Example Service][4]
* [go-kit][5][1]: http://www.grpc.io/
[2]: https://github.com/docker/compose/issues/3560
[3]: https://speakerdeck.com/mattheath/scaling-microservices-in-go-high-load-strategy-2015
[4]: https://github.com/grpc/grpc-go/tree/master/examples/route_guide
[5]: https://github.com/go-kit/kit
[6]: https://github.com/harlow/go-micro-services/graphs/contributors