shenyu-plugin-tars
org.apache.shenyu.plugin.tars.TarsPlugin
<dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-client-tars</artifactId> <version>${shenyu.version}</version> </dependency>
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()); } }
shenyu-admin
--> 基础配置 --> 插件管理-> tars
,设置为开启。multiSelectorHandle
:设置为可以多个选择器处理,在选择器列表可配置多个选择器处理服务。multiRuleHandle
:设置为可以多个规则处理,在规则列表配置多个处理规则,建议配置为 single rule。threadpool
:业务线程池类型,有fixed
、eager
、cached
、limited
和shared
共5种类型,前面4种与dubbo官方提供的线程池一一对应,不多解释,这里单独说下shared
,正如其名,所有proxy插件
共用一个shared
线程池,这样做的好处是能够减少线程池数量,进而降低内存、提高资源利用率。corethreads
:业务线程池核心线程数。threads
:业务线程池最大线程数。queues
:业务线程池阻塞队列长度,0表示无界阻塞队列
。流量需要经过选择器匹配。
@ShenyuTarsClient
注解自动配置选择器。流量经过选择器匹配成功之后,会进入规则来进行最终的流量匹配。
@ShenyuTarsClient
注解自动配置规则。当
Tars
应用客户端接入到Apache ShenYu
网关时,会自动注册,可以在shenyu-admin
后台管理系统的基础配置-->
元数据管理中查看,每一个Tars
接口方法,都会对应一条元数据。
应用名称:该条元数据所属的应用名称。
方法名称:需要调用的方法名。
路径:http
请路径。
路径描述:对该路径的说明,方便查看。
参数类型:按照接口的参数类型顺序。
Rpc扩展参数:接口的扩展参数配置,json
格式。
示例:{"loadbalance":"hash","retries":3,"timeout":-1}
loadbalance
:负载均衡策略,当前支持 roundRobin、random 和 hash。retries
:调用客户端超时失败的重试次数。timeout
:调用客户端的超时时间。服务接口:Tars
接口的全限定类名。
Rpc
类型:自动注册默认为 tars
。
ShenYu Admin
。Shenyu Bootstrap
。shenyu-admin
--> 基础配置 --> 插件管理-> tars
,设置为开启。