Web 快速使用 gRPC

更新时间: 2019-07-05 12:52

This guide gets you started with gRPC-Web with a simple working example.

Prerequisites

  • docker and docker-compose

This demo requires Docker Compose file version 3. Please refer to Docker website on how to install Docker.

Run an Echo example from the browser!

$ git clone https://github.com/grpc/grpc-web
$ cd grpc-web
$ docker-compose pull
$ docker-compose up -d node-server envoy commonjs-client

Open a browser tab, and go to:

http://localhost:8081/echotest.html

To shutdown, run docker-compose down.

What is Happening?

In this demo, there are three key components:

  1. node-server: This is a standard gRPC Server, implemented in Node. This server listens at port :9090 and implements the service’s business logic.
  2. envoy: This is the Envoy proxy. It listens at :8080 and forwards the browser’s gRPC-Web requests to port :9090. This is done via a config file envoy.yaml.
  3. commonjs-client: This component generates the client stub class using the protoc-gen-grpc-web protoc plugin, compiles all the JS dependencies using webpack, and hosts the static content echotest.html anddist/main.js using a simple web server at port :8081. Once the user interacts with the webpage, it sends a gRPC-Web request to the Envoy proxy endpoint at :8080.

What’s next

众媒时代

众媒时代

腾讯传媒研究 / 中信出版集团股份有限公司 / 2016-3-1 / CNY 52.00

众媒时代,就是一个大众参与的媒体时代。互联网将传统媒体垄断而单一的传播方式彻底颠覆。人人都可以通过互联网成为内容的制造者、传播者。每个人都是媒体,人是种子,媒体变成了土壤。 当我们的信息入口被朋友圈霸占,当我们的眼睛只看得到10W+,当我们不可抑制地沉浸在一次次的“技术狂欢”中,当人人都可以举起手机直播突发现场,当未来的头条由机器人说了算……内容正生生不息地以各种可能的形式出现,我们正彻头彻......一起来看看 《众媒时代》 这本书的介绍吧!

JSON 在线解析

JSON 在线解析

在线 JSON 格式化工具

正则表达式在线测试

正则表达式在线测试

正则表达式在线测试

HEX HSV 转换工具

HEX HSV 转换工具

HEX HSV 互换工具