This topic describes the complete procedure for service throttling, from local project development to cloud application deployment and configuration.
Procedure
Develop the project locally.
For more information, see Implement an SOFARPC service locally.
Import dependencies and configure them locally.
Import dependencies
In the
pom.xmlfile of theendpointmodule in your SOFABoot web project, import the DRM and guardian dependencies as follows:<dependency> <groupId>com.alipay.sofa</groupId> <artifactId>ddcs-enterprise-sofa-boot-starter</artifactId> </dependency> <dependency> <groupId>com.alipay.sofa</groupId> <artifactId>guardian-sofa-boot-starter</artifactId> </dependency>Using
rest-enterprise-sofa-boot-starterandrpc-enterprise-sofa-boot-starterWhen importing
rpc-enterprise-sofa-boot-starter, also import the following dependencies to enable the service throttling feature. Otherwise, service throttling will not work.<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> </dependency> <dependency> <groupId>com.alipay.sofa</groupId> <artifactId>tracer-enterprise-sofa-boot-starter</artifactId> </dependency>When you define an interface, also define a custom exception and an exception handler. This lets you throw an exception when a request is throttled and return the result to the frontend.
Local configuration
After you import the
guardian-sofa-boot-starterdependency, the application can throttle SOFARPC interfaces and Spring MVC requests. To also throttle methods defined in internal Spring Beans, add an AOP interceptor configuration to the Spring Bean configuration file as follows:<!-- Import the bean defined in guardian. --> <import resource="classpath:META-INF/spring/guardian-sofalite.xml"/> <!-- Configure the AOP interceptor. --> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="interceptorNames"> <list> <value>guardianExtendInterceptor</value> </list> </property> <property name="beanNames"> <list> <!-- Configure the beans to be intercepted. --> <value>*DAO</value> </list> </property> <!-- To use a CGLIB proxy, uncomment the following line. --> <!-- <property name="optimize" value="true" /> --> </bean>
Publishing to the cloud.
For deployment instructions, see the following topics:
For an overview of the deployment flow, see Technology Stack Guide.
For detailed deployment steps, see Quick Start.
Configure service throttling rules in the SOFAStack console.
For more information, see Configure service throttling rules in the console.