Closed nadilas closed 5 years ago
there ins't one currently, gRPC just stops via normal signals. But I'm open to a better running that listens to signal that we can act on. It would be useful for draining subscribers too.
I'll put one in with consul in one go. We can discuss from there
So here's what I've got so far: https://github.com/nadilas/lile
The templates are supposed to be updated, although I haven't done a clean install test yet. I will do that later.
first:
consul agent -dev
server:
go run service/main.go up --pubsub --consul --service_port=8555
time="2018-03-18T14:29:49+01:00" level=warning msg="Using noop pubsub provider"
time="2018-03-18T14:29:49+01:00" level=info msg="Regsitered service 'srvsearch-4485272b-a433-49cb-bf43-699369a58a77' at consul."
time="2018-03-18T14:29:49+01:00" level=info msg=Subscribing...
time="2018-03-18T14:29:49+01:00" level=info msg="Serving gRPC on localhost:8555"
time="2018-03-18T14:29:49+01:00" level=info msg="Using Zipkin HTTP tracer: http://localhost:9411/api/v1/spans"
time="2018-03-18T14:29:49+01:00" level=info msg="Prometheus metrics at http://localhost:9555/metrics"
time="2018-03-18T14:29:57+01:00" level=info msg="Captured interrupt. Exiting..."
time="2018-03-18T14:29:57+01:00" level=info msg="Shutting gRPC service 'srvsearch'"
time="2018-03-18T14:29:57+01:00" level=info msg="Deregistered service 'srvsearch-4485272b-a433-49cb-bf43-699369a58a77' at consul."
time="2018-03-18T14:29:57+01:00" level=info msg=Unsubscribing...
Process finished with exit code 0
client:
INFO[0000] Creating srvsearch gRPC client
INFO[0000] read from service: id:"created at server"
Looks like a good start! Can you make a pull-request and we'll go through it?
Some first thoughts. I quite like to the move to AppConfig or something similar, but I would like to keep pubsub and consul abstracted away, I moved pubsub to https://github.com/lileio/pubsub and it's been good as internal we not use that without any gRPC logic at all.
So perhaps we should make Registery
an interface? During generation we could allow the passing flags like --pubsub --consul to generate the required parts.
The shutdown hook is great and I definitely get that support into pubsub ASAP, I'm working on a v2 branch here with middleware etc https://github.com/lileio/pubsub/tree/v2
Making the registry pluggable is definitely a great idea! I'll leave it for this PR as is, but I'll extract it out later this week. Would you open a lileio/registry
repo? Then I can create a PR against it later this week. I'd even go as far as:
--pubsub=gcloud --registry=consul
having pluggable implementations for registry then: consul,zookeeper, etc...
My problem with AppConfig was that I couldn't get cobra/viper to read the cli arg as an env var at the same time, I'm sure it's possible I just didn't want to spend too much time on it initially. Ideal would be a setup like in this flag implementation: https://github.com/ogier/pflag.
pubsub V2 looks nice! I just moved the pubsub.Subscribe()
to the main Run() in the core, but based on user flags and an interfaced pubsub initialization --pubsub=gcloud
it will even be better.
As discussed a consul integration would be nice. I am currently looking at a shutdown hook, to deregister the service. I can't seem to find, where do you stop the service?