Micro_SideCar HTTP接口 Micro_SideCar

blov • 3748 次点击    
这是一个分享于 的项目,其中的信息可能已经有所发展或是发生改变。
# Micro SideCar SideCar 提供了一个 集成应用程序到微型 生态系统 的HTTP接口 。 它类似于 Netflix 称为Prana 的SideCar。 ** 特性 ** * 登记 发现系统 * 主机 的 其他 服务发现 * 健康检查服务 * HTTP API 和负载平衡 要求 * 通过 PubSub的 的WebSockets ** 入门 ** **安装** <pre class="brush:shell;toolbar: true; auto-links: false;">go get github.com/micro/micro</pre> **运行** micro sidecar默认在端口8081 运行 。 开始 sidecar <pre class="brush:shell;toolbar: true; auto-links: false;">micro sidecar</pre> 如果你想在启动程序自动 登记 一个应用程序 可以选择指定 的应用程序 服务器 名称和地址。 <pre class="brush:shell;toolbar: true; auto-links: false;">micro sidecar --server_name=foo --server_address=127.0.0.1:9090</pre> ** 服务安全 TLS ** Sidecar 支持 TLS证书 的安全 服务 <pre class="brush:shell;toolbar: true; auto-links: false;">micro --enable_tls --tls_cert_file=/path/to/cert --tls_key_file=/path/to/key sidecar</pre> ** 主机发现 ** <pre class="brush:shell;toolbar: true; auto-links: false;">curl http://127.0.0.1:8081/registry?service=go.micro.srv.example {     &#34;name&#34;:&#34;go.micro.srv.example&#34;,        &#34;nodes&#34;:[{          &#34;id&#34;:&#34;go.micro.srv.example-c5718d29-da2a-11e4-be11-68a86d0d36b6&#34;,            &#34;address&#34;:&#34;[::]&#34;,&#34;port&#34;:60728     }] }</pre> ** 注册/ 注销 服务 ** 注册 <pre class="brush:shell;toolbar: true; auto-links: false;">curl -H &#39;Content-Type: application/json&#39; http://127.0.0.1:8081/registry -d  {     &#34;Name&#34;: &#34;foo.bar&#34;,      &#34;Nodes&#34;: [{         &#34;Port&#34;: 9091,          &#34;Address&#34;: &#34;127.0.0.1&#34;,             &#34;Id&#34;: &#34;foo.bar-017da09a-734f-11e5-8136-68a86d0d36b6&#34;     }] }</pre> 注销 <pre class="brush:shell;toolbar: true; auto-links: false;">curl -X &#34;DELETE&#34; -H &#39;Content-Type: application/json&#39; http://127.0.0.1:8081/registry -d  {     &#34;Name&#34;: &#34;foo.bar&#34;,      &#34;Nodes&#34;: [{                &#34;Port&#34;: 9091,                &#34;Address&#34;: &#34;127.0.0.1&#34;,               &#34;Id&#34;: &#34;foo.bar-017da09a-734f-11e5-8136-68a86d0d36b6&#34;     }] }</pre> **健康检查** 利用“--healthcheck_url=” 启用micro sidecar使得 健康 检查工作 <pre class="brush:shell;toolbar: true; auto-links: false;">$ micro sidecar --server_name=foo --server_address=127.0.0.1:9090 \     --healthcheck_url=http://127.0.0.1:9090/_status/health I0523 12:25:36.229536   85658 car.go:184] Registering foo-6ebf29c0-013e-11e5-b55f-68a86d0d36b6 I0523 12:25:36.241680   85658 car.go:188] Starting sidecar healthchecker</pre> ** HTTP RPC API ** 通过http rpc api查询micro 服务。 <pre class="brush:shell;toolbar: true; auto-links: false;">$ curl  -d &#39;service=go.micro.srv.example&#39; \     -d &#39;method=Example.Call&#39; \     -d &#39;request={&#34;name&#34;: &#34;John&#34;}&#39; http://127.0.0.1:8081/rpc {&#34;msg&#34;:&#34;go.micro.srv.example-c5718d29-da2a-11e4-be11-68a86d0d36b6: Hello John&#34;}</pre> ** 通过WebSockets的 PubSub ** 通过 WebSocket的 接口连接到micro的 Pub/Sub <pre class="brush:shell;toolbar: true; auto-links: false;">c, _, _ := websocket.DefaultDialer.Dial(&#34;ws://127.0.0.1:8081/broker?topic=foo&#34;, make(http.Header)) go func() {        for {               _, p, err := c.ReadMessage()                if err != nil {                       return        }               var msg *broker.Message        json.Unmarshal(p, &amp;msg)        fmt.Println(msg.Data)    } }() ticker := time.NewTicker(time.Second) for _ = range ticker.C {        if err := c.WriteMessage(1, []byte(`hello world`)); err != nil {                return     } }</pre> ** 代理CLI 请求 ** sidecar还充当CLI 代理 <pre class="brush:shell;toolbar: true; auto-links: false;">$ micro --proxy_address=127.0.0.1:8081 list services go.micro.srv.greeter</pre> ** 统计仪表板 ** 您可以通过--enable_stats旗子启动 统计 仪表板。 它将在 /统计中 显示出来。 <pre class="brush:shell;toolbar: true; auto-links: false;">micro --enable_stats sidecar</pre> ![image](http://static.oschina.net/uploads/img/201603/22143329_oYI4.png)
授权协议:
Apache
开发语言:
Google Go 查看源码»
操作系统:
跨平台
3748 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传