1. 概述
1.1 插件名称
- Tars插件
1.2 适用场景
- 协议转换,将 http 协议的请求转换成 Tars 框架协议的服务处理的插件
- 服务负载均衡
1.3 插件功能
- 将 http 协议的请求转换成 Tars 框架协议
1.4 插件代码
- 核心模块
shenyu-plugin-tars - 核心类
org.apache.shenyu.plugin.tars.TarsPlugin
1.5 添加自哪个shenyu版本
- 2.3.0
2. 如何使用插件
2.1 插件使用流程图

2.2 导入pom
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-client-tars</artifactId>
<version>${shenyu.version}</version>
</dependency>
2.3 在客户端项目中配置
- 在 application.yml 中配置 Tars 的配置
shenyu:
register:
registerType: http #zookeeper #etcd #nacos #consul
serverLists: http://localhost:9095 #localhost:2181 #http://localhost:2379 #localhost:8848
props:
username: admin
password: 123456
client:
tars:
props:
contextPath: /tars
appName: tars
port: 21715
host: 192.168.41.103 # client IP
- 在接口上添加
@ShenyuTarsService和@ShenyuTarsClient注解
@TarsServant("HelloObj")
@ShenyuTarsService(serviceName = "ShenyuExampleServer.ShenyuExampleApp.HelloObj")
public class HelloServantImpl implements HelloServant {
@Override
@ShenyuTarsClient("/hello")
public String hello(final int no, final String name) {
return String.format("hello no=%s, name=%s, time=%s", no, name, System.currentTimeMillis());
}
}