Grpc-http gateway I

This is the second day of my participation in Gwen Challenge

What is gRPC? Let’s go back a little bit

GRPC is a generic, high-performance RPC framework developed by Google and designed based on the HTTP/2 standard. It has the following three most obvious features:

  • Support for major programming languages,C++, Java, Python, Go, RubyAnd so on, based onProtoBufGenerate the corresponding server and client code.
  • Based on THE HTTP/2 protocol, and provides stronger application performance – bandwidth saving, reduce the number of TCP connection requests
  • Based on theProtoBufDefine services and design them for interfaces

Specifically, this article has been introduced to the introduction of gRPC

What is an HTTP gateway?

Before we share gRPC’s HTTP gateway, let’s talk about what an HTTP gateway is

What is a gateway?

A Gateway is a Gateway through which one network connects to another.

A gateway is a device that connects two network segments using different transport protocols. A gateway is generally used as an entry and exit point for the network because all data must pass through or communicate with the gateway before routing.

Gateway All networks have a boundary that restricts communication with devices directly connected to it. If networks want to communicate with devices, nodes, or networks outside this boundary, they need gateway functionality. A gateway is usually represented as a combination of router and modem.

The HTTP gateway, understandably, is a network gateway based on HTTP requests

What are HTTP gateways?

  • HTTP/*, server-side Web gateway

For example, when a client downloads resources from the network, the client accesses the Web gateway through HTTP. After the Web gateway identifies the request, it requests the FTP server to upload and download files

  • HTTP/HTTPS: server-side security gateway

Security gateway, you can think of encryption

The gateway encrypts all incoming Web requests to provide additional privacy and security. Even though the client can browse Web content using ordinary HTTP, the gateway automatically encrypts user conversations to ensure security

  • HTTPS/HTTP client security accelerator gateway

HTTPS is added before HTTP requests to ensure traffic security

Using HTTPS/HTTP gateways as security accelerators, these HTTPS/HTTP gateways are typically used as invisible intercepting gateways or reverse proxies before being placed on a Web server. They receive secure HTTPS processed traffic, decrypt secure traffic, and send plain HTTP requests to Web servers

That is, under normal circumstances, if traffic can reach the Web, it is safe

  • Other Resource Gateways

For example, to access the internal data of some applications, this is the gateway that connects the client to the server over the network.

That is, the gateway is on the server corresponding to the application program, communicates with the client through HTTP/HTTPS, and connects to the application program on its own server

gRPC-Gateway

When Golang is developed, gRPC is generally used internally for internal communication between microservices, with HTTP interfaces exposed and provided to the front end or client.

In our micro service, we should not only have gRPC for internal communication, but also write exposed HTTP interface, which seems to increase a lot of work virtually, and maintain two versions of the service, isn’t it very low? So is there a way to combine, or simplify, these two approaches?

Of course there is, gRPC provides us with a very convenient GRPC-Gateway plug-in

What is grPC-gateway?

An excellent plugin for Protoc

Grpc-gateway provides the ability to generate HTTP reverse proxies based on service interface definitions in proto files. For the same standard gRPC service definition, in addition to the basic gRPC client can also generate the corresponding HTTP JSON interface implementation code

It can through Google provides a standard interface Google/API/annotations. The proto, we can the original Protobuf service, described its corresponding form of HTTP interface

So this is the structure

What are the advantages of GRPC-Gateway?

Yes, we write micro services, internal use gRPC, external use HTTP, a service inside write 2 sets of interfaces, tired is a bit tired, but grPC-gateway just write gRPC service can also be used for HTTP interface?

Of course not

The advantages of using GRPC-Gateway are as follows:

  • You can keep it Restful

Grpc-gateway tool, so that we can very quickly based on proto interface definition, while using RPC to provide external Restful

Using gRPC’s original Protobuf service can also feel Restful simplicity, like a direct write HTTP interface, easy to use

  • It also improves the performance and reliability of applications

This is the strength of the RPC framework, which is designed for high performance and high productivity design in distributed applications

What are the considerations when using gRPC to provide HTTP interfaces?

  • GRPC provides an HTTP interface based onThe HTTP 2.0the
  • Just don’t get too excited

conclusion

  • reviewgRPCThe bottom line
  • Introduction to HTTP gateways
  • Which leads to thegRPC-gatewayAnd its basic structure

Well, this time here, next time to share the grPC-Gateway actual environment construction, case coding, debugging skills, and effect output

Technology is open, our mentality, should be more open. Embrace change, live in the sun, and strive to move forward.

I am Nezha, welcome to like, see you next time ~