This is the 31st day of my participation in the August More Text Challenge

If ❤️ my article is helpful, welcome to like, follow. This is the biggest encouragement for me to continue my technical creation. More previous articles in my personal column

Thrift service proxy setup

TCP proxy tests multiple protocols

  • The proxy tests thrift recommendations
  • Agent testing redis recommendations
  • Proxy testing websocket is not recommended
  • Proxy testing HTTP/HTTPS is not recommended

It is not recommended to use TCP for proxy because it is too simple

TCP Proxy Features

  • Streaming data and stateless data (without headers/cookies) are recommended
  • Less control of service management, can only doFlow controlandRequest Source restriction
  • If there is a protocol proxy, it is recommended to use HTTP /websocket.

The TCP proxy tests thrift

  • Thrift installation reference: thrift.apache.org/docs/instal…
  • Thrift is introduced
    • An open source project from Facebook that was later incubated at Apache
    • Thrift also supports cross-language support, so it has its own set of IDLs
    • Thrift’s network protocol is based on TCP
    • Currently the main function is to support RPC method calls
  • Build thrift test Server and Client
  • Agent for the test

Build thrift test Server and Client

  • First of all to writethrift_ gen.thniftThrift configuration file
  • Run the IDL generation command to generate the server/client structure ‘thrift –gen go thrift_gen. Thrift ‘
  • Use the generated IDL to build the server and client separately

First of all to writethrift_ gen.thniftThrift configuration file

pratise/proxy/thrift_server_client/thrift_ gen.thnift

namespace go thrift_gen

struct Data {
    1: string text
}

service format_data {
    Data do_format(1:Data data),
}
Copy the code

Go to the pratise/proxy/thrift_server_client directory. Run the thrift –gen go thrift_gen.thrift command to generate template code

/d/Dev/env/thrift014/thrift014.exe –gen go thrift_gen.thnift

The directory pratise/proxy/thrift_server_client/gen-go is generated

Pay attention to

The version of the thrift command must be consistent with the golang project installation version. Otherwise the generated code may report an error

Viewing the Version

$/ d/Dev/env/thrift014 thrift011. Exe – version Thrift version 0.14.2

The generated IDL is used to build the server and client separately

Client code: Pratise /proxy/thrift_server_client/thriftclient_main/main.go Server code: pratise/proxy/thrift_server_client/thriftserver_main/main.go

Test the server and client

Pratise /proxy/thrift_server_client/ thriftServer_main /main.go Code for starting a client: pratise/proxy/thrift_server_client/thriftclient_main/main.go

The installation of thrift 0.11.0 fails

Solution: Download the thrift 0.11.0 version yourself. Publish a Go Module yourself

test

# start server
go run thriftserver_v1/main.go


Start the client
go run thriftclient_v1/main.go
Copy the code

Copy: D:\Dev\env\golang\bin\pkg\mod\git.apache.org \ [email protected] \ tutorial \ go \ SRC

Then, open another terminal, change the server from main to false as described in the previous section, and run again.

Administrator@DESKTOP-U15QB8I MINGW64 /d/Dev/workplace/golang/gateway_v1/pratise/proxy/thrift_server_client/thrift_v1 (master)
$ go run main.go server.go client.go handler.go
handler.go:25:2: package shared is not in GOROOT (D:\Dev\env\golang\src\shared)
server.go:26:2: package tutorial is not in GOROOT (D:\Dev\env\golang\src\tutorial)
Copy the code