NEED HELP! Implementing microservices

agolangf · · 595 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>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 &#34;/about&#34;, the mux will reroute the request to a &#34;about&#34; service waiting on port X.</p> <hr/>**评论:**<br/><br/>sethammons: <pre><p>General advice: don&#39;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 ;). </p> <p>If you don&#39;t want to use something like <a href="https://github.com/go-kit/kit" rel="nofollow">go-kit</a> or <a href="https://github.com/micro/go-micro" rel="nofollow">go-mircro</a>, you can just just run one go service at <code>:$PortA</code> and run a different service at <code>:$PortB</code> using the standard http library. So service A would allow something like <code>curl localhost:$PortA/about</code> and when that request comes in, service A would call service B like: <code>resp, err := http.Get(fmt.Sprintf(&#34;http://localhost:%d/b-specific-page-for-about&#34;, PortB))</code>. This means that <code>curl localhost:$PortB/b-specific-page-for-about</code> would return the same as the previous curl. One just calls the other. </p></pre>jasonrichardsmith: <pre><p>I feel like I am opening a Pandora&#39;s box of &#34;can you do this for me,&#34; but for anyone else curious.</p> <p>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&#39;/instances&#39; 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.</p> <p>I don&#39;t really think you are ready for all of this.</p></pre>orbat: <pre><p>I&#39;d suggest reading into what microservices are, for example <a href="https://www.nginx.com/blog/introduction-to-microservices/" rel="nofollow">here</a></p></pre>cube2222: <pre><p>You can also check out my series: <a href="https://jacobmartins.com/2016/03/14/web-app-using-microservices-in-go-part-1-design/" rel="nofollow">https://jacobmartins.com/2016/03/14/web-app-using-microservices-in-go-part-1-design/</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

595 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传