A tars protocol proxy that supports the tars-tars protocol, tars-tup protocol, and tars-json protocol.
There are two main application scenarios:
- Forwarding access as tars protocol;
- Transparent forwarding for TARS requests across IDC.
In addition to supporting basic protocol forwarding, ProtocolProxyServer also provides IP authorization for the called service and interface.
Tarsprotocol Proxy works on the 4th Layer network, which obtains the buffer directly and parses the Tars request packages and forwards them according to fields in the body of request packages. For more information about the format of the request and response package, see the document of Message Format.
The configuration file ProtocolProxyServer.conf
is used to configure the proxy server, which uses the XML
style, the same as the TARS server's configuration file.
The root node is conf
. There is an attribute tarsping_interval
, which is used to configure the interval of the heartbeat request, in seconds, and 0
means to disable. As follows
<conf>
tarsping_interval=10
...
</conf>
In node conf
, there are proxy
, proxy_conn
and auth
nodes can be configured, which are proxy, keep-alive connection, and IP authentication configuration respectively.
In node proxy
, the proxy information of the server's Obj
can be configured that the proxy server can forward the request directly without obtaining the address from the registry server.
<conf>
...
<proxy>
Test.SumClientServer.SumClientObj1=Test.SumClientServer.SumClientObj@tcp -h 172.16.8.147 -t 60000 -p 10032
</proxy>
...
</conf>
Node proxy_conn
can configure which Obj
use keep-alive connection.
<conf>
...
<proxy_conn>
Test.GetSum22Server.GetSumObj = Base.ProtocolProxyServer.TarsProxyObj@tcp -h 172.16.8.115 -t 60000 -p 8888
</proxy_conn>
...
</conf>
Node auth
can add configuration for IP authentication. In this node, you can add several nodes according to your business and configure for each business. It doesn't matter what the node name is, just keep each unique.
ip_white_list
and ip_black_list
are used for global configuration.
<auth>
# Enable IP auth with value on, disable with value off.
# (Any IP can access the server in the cluster with value off, which is normally used in intranet)
on_off=off
# Configured by the business for convenient management.
# The business name here has no actual meaning, as long as it is unique.
<test_buss_1>
# obj = white ip
Test.GetSumServer.GetSumObj=124.74.236.120|124.74.236.122
</test_buss_1>
<news>
News.HelloServer.HelloObj=124.74.236.11|124.74.236.12
</news>
# Add IP white and black list globally.
ip_white_list=1.1.1.1|2.2.2.2
ip_black_list=3.3.3.3
</auth>
The following is the example for a configuration file
<conf>
tarsping_interval=10
<proxy>
Test.SumClientServer.SumClientObj1=Test.SumClientServer.SumClientObj@tcp -h 172.16.8.147 -t 60000 -p 10032
Test.TestServer.TestObj=Test.TestServer.TestObj@-h 192.168.242.176 -p 8888 -t 60000
</proxy>
<proxy_conn>
Test.GetSum22Server.GetSumObj = Base.ProtocolProxyServer.TarsProxyObj@tcp -h 172.16.8.115 -t 60000 -p 8888
</proxy_conn>
<auth>
on_off=off
<test_buss_1>
Test.GetSumServer.GetSumObj=124.74.236.120|124.74.236.122
</test_buss_1>
<news>
News.HelloServer.HelloObj=124.74.236.11|124.74.236.12
</news>
ip_white_list=1.1.1.1|2.2.2.2
ip_black_list=3.3.3.3
</auth>
</conf>
The protocol proxy server is essentially a TARS server, so the deployment process is similar.
Execute the following command to compile the server and generate release package.
mkdir build
cd build
cmake ..
make
make tar
In tab operation -> Manage Template
of TarsWeb, click add Template
,
Template
: Can be customized, here we fill inBase.ProtocolProxyServer
Parent template
:tars.default
content
: As follows
<tars>
<application>
<server>
deactivating-timeout=3000
openthreadcontext=0
threadcontextnum=10000
threadcontextstack=32768
</server>
<client>
sync-invoke-timeout=5000
async-invoke-timeout=20000
sample-rate=1000
max-sample-count=100
sendthread=1
recvthread=1
</client>
</application>
</tars>
Click OK
to generate the template.
In tab operation -> Deploy service
of TarsWeb
APP
:Base
Service name
:ProtocolProxyServer
Service type
:tars_cpp
Template
:Base.ProtocolProxyServer
OBJ
:TarsProxyObj
Protocol
:not TARS
Click get port
to automatically generate the port(It is recommended to use a fixed port 8300).
We need to upload the configuration file mentioned before, that the server can load it while starting.
Go to the service configuration of ProtocolProxyServer
in TarsWeb, and click add configuration
Fill in the fileName
and content
in the pop-up window
Click OK
to finish it.
Go to tab Publish
of this server to upload the release package and publish the server.