shenyu-plugin-sofa
org.apache.shenyu.plugin.sofa.SofaPlugin
<dependency> <groupId>com.alipay.sofa</groupId> <artifactId>rpc-sofa-boot-starter</artifactId> <version>${rpc-sofa-boot-starter.version}</version> </dependency> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-client-sofa</artifactId> <version>${project.version}</version> <exclusions> <exclusion> <artifactId>guava</artifactId> <groupId>com.google.guava</groupId> </exclusion> </exclusions> </dependency>
com: alipay: sofa: rpc: registry-address: zookeeper://127.0.0.1:2181 # consul # nacos bolt-port: 8888 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: sofa: props: contextPath: /sofa ipAndPort: sofa appName: sofa port: 8888
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sofa="http://sofastack.io/schema/sofaboot" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://sofastack.io/schema/sofaboot https://sofastack.io/schema/sofaboot.xsd" default-autowire="byName"> <!-- 示例 sofa 接口 --> <sofa:service ref="sofaSingleParamService" interface="org.apache.shenyu.examples.sofa.api.service.SofaSingleParamService"> <sofa:binding.bolt/> </sofa:service> <!-- 示例 sofa 接口 --> <sofa:service ref="sofaMultiParamService" interface="org.apache.shenyu.examples.sofa.api.service.SofaMultiParamService"> <sofa:binding.bolt/> </sofa:service> </beans>
@ShenyuSofaClient
annotation to the interface.@ShenyuSofaClient("/demo") @Service public class SofaClientMultiParamServiceImpl implements SofaClientMultiParamService { @Override @ShenyuSofaClient("/findByIdsAndName") public SofaSimpleTypeBean findByIdsAndName(final List<Integer> ids, final String name) { return new SofaSimpleTypeBean(ids.toString(), "hello world shenyu sofa param findByIdsAndName :" + name); } }
In shenyu-admin --> BasicConfig --> Plugin --> sofa
set Status enabled.
protocol
: Register center protocol, currently supports zookeeper、consul、nacos.register
: The service IP and PORT of the registry.threadpool
:There are five types of business thread pools: fixed
, eager
, cached
, limited
and shared
. The first 4 types correspond to the thread pools officially provided by dubbo. Let's talk about shared
, as its name implies, all proxy plugins
share a shared
thread pool, the advantage of this is that it can reduce the number of thread pools, thereby reducing memory and improving resource utilization.corethreads
:The number of core threads in the business thread pool.threads
:The maximum number of threads in the business thread pool.queues
:The length of the blocking queue of the business thread pool, 0 means unbounded blocking queue
.Flow needs to be matched by selector.
@ShenyuSofaClient
annotation.After the traffic has been successfully matched by the selector, it will enter the rules for the final traffic matching.
@ShenyuSofaClient
annotation.When the
sofa
application client accesses theApache ShenYu
gateway, it will be automatically registered, and can be viewed in the-shenyu-admin
backend management system's basic configuration-->
metadata management, eachsofa
interface method, will correspond to a metadata.
AppName: specifies the name of the application to which the metadata belongs.
MethodName: the name of the method to call.
Path: http request path.
PathDescribe: the description of the path is easy to view.
ParamsType: the parameters are separated by commas (,) in the order of interface parameter types.
RpcExpand: other configurations of the sofa
interface, which support the JSON
format.
examples:{"loadbalance":"hash","retries":3,"timeout":-1}
loadbalance
:Load balancing policy, currently supports roundRobin, random and hash.retries
:Number of retries to call client timeout failures.timeout
:Calling the client's timeout time.Interface: The fully qualified class name of the sofa
interface.
RpcType:choose sofa
.
Zookeeper
service.ShenYu Admin
.Shenyu Bootstrap
.sofa
set Status enabled, And adjust the registry configuration as needed.shenyu-admin
--> BasicConfig --> Plugin --> sofa
set Status disable.