hi fellow gophers! I am trying to build a mini project comprising of microservices. Sorry for the noob question, how can I call the other services? I have a gorilla mux. What I want to happen is when I issue the GET "/about", the mux will reroute the request to a "about" service waiting on port X.
评论:
sethammons:
jasonrichardsmith:General advice: don't use microservices until it makes sense to do so. Only break the application apart when you need to independently scale that part of your service. Microservices can also be helpful when you have multiple teams, allowing a team to deploy on their own schedule. In this case, an about page probably does not need to be independently scaled or have its own dev team ;).
If you don't want to use something like go-kit or go-mircro, you can just just run one go service at
:$PortA
and run a different service at:$PortB
using the standard http library. So service A would allow something likecurl localhost:$PortA/about
and when that request comes in, service A would call service B like:resp, err := http.Get(fmt.Sprintf("http://localhost:%d/b-specific-page-for-about";, PortB))
. This means thatcurl localhost:$PortB/b-specific-page-for-about
would return the same as the previous curl. One just calls the other.
orbat:I feel like I am opening a Pandora's box of "can you do this for me," but for anyone else curious.
It is pointless to route your urls directly to a microservice, since one of the points of these services is to horizontally scale. For that to happen you need a proper service discovery system. You can use Consul , and have your individual vms'/instances' DNS point to the Consul DNS service, or you can use Etcd with Vulcand as a router. You can use either Etcd or Consul to reload HaProxy. You can also use these with Zookeeper, but I am not altogether familiar with that.
I don't really think you are ready for all of this.
cube2222:I'd suggest reading into what microservices are, for example here
You can also check out my series: https://jacobmartins.com/2016/03/14/web-app-using-microservices-in-go-part-1-design/
