在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:forest开源软件地址:https://gitee.com/dempe/forest开源软件介绍:ForestOverview基于netty轻量的高性能分布式RPC服务框架。简单,易用,高效。 Features
ProtocolQuick StartAdd dependencies to pom. <dependency> <groupId>com.zhizus</groupId> <artifactId>forest-rpc</artifactId> <version>0.0.2</version></dependency><dependency> <groupId>com.zhizus</groupId> <artifactId>forest-common</artifactId> <version>0.0.2</version></dependency> 1.定义接口
@ServiceProvider(serviceName = "sampleService", haStrategyType = HaStrategyType.FAIL_FAST, loadBalanceType = LoadBalanceType.RANDOM, connectionTimeout = Constants.CONNECTION_TIMEOUT)public interface SampleService { @MethodProvider(methodName = "say") String say(String str); @MethodProvider(methodName = "echo", serializeType = SerializeType.Hession2, compressType = CompressType.None) String echo(String msg);} 2.实现接口
@Path("/sample")@ServiceExportpublic class SampleServiceImpl implements SampleService { /** * 支持jersey,可以通过配置打开,同时启动http服务 * * @param str * @return */ @Path("/hello/{str}") @GET @Produces("text/plain") @MethodExport @Rate(2) @Override public String say(@PathParam("str") String str) { return "say " + str; } @Interceptor("metricInterceptor") @MethodExport @Override public String echo(String msg) { return "echo>>> " + msg; }} 3.服务端开发spring context 配置:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans" xmlns:forest="http://api.zhizus.com/schema/forest" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://api.zhizus.com/schema/forest http://api.zhizus.com/schema/forest.xsd"> <context:component-scan base-package="com.zhizus.forest.demo"/> <context:property-placeholder location="classpath:/*.properties"/> <forest:registry id="registry" regProtocol="local" name="registry" address="127.0.0.1:2181"/> <!--<forest:registry id="registry" regProtocol="zookeeper" name="registry" address="127.0.0.1:2181"/>--> <forest:server id="forestServer" registry="registry" startHttpServer="true"/> <forest:interceptors> <forest:interceptor id="metricInterceptor" class="com.zhizus.forest.support.MetricInterceptor" auto-match="public *(*)"/> </forest:interceptors></beans> Server开发public class SampleServer { public static void main(String[] args) throws Exception { new ClassPathXmlApplicationContext(new String[]{"application.xml"}); }} 4.客户端开发<?xml version="1.0" encoding="UTF-8"?><beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:forest="http://api.zhizus.com/schema/forest" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://api.zhizus.com/schema/forest http://api.zhizus.com/schema/forest.xsd"> <context:component-scan base-package="com.zhizus.forest.demo.client"/> <forest:registry id="registry" regProtocol="local" name="registry" address="127.0.0.1:9999"/> <forest:referer id="sampleService" interface="com.zhizus.forest.demo.api.SampleService" registry="registry"> <forest:method name="echo" timeout="5000" serializeType="Fastjson"/> <forest:method name="say" timeout="5000" serializeType="Fastjson" compressType="GZIP"/> </forest:referer></beans> ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"application-client.xml"}); SampleService bean = (SampleService) context.getBean("sampleService"); String test = bean.say("hello"); Console输出23:10:10.295 [pool-1-thread-1] INFO MetricInterceptor 34 - methodName:/sampleService/say, current tps:83342, avgTime:0, maxTime:63, minTime:023:10:11.298 [pool-1-thread-1] INFO MetricInterceptor 34 - methodName:/sampleService/say, current tps:86271, avgTime:0, maxTime:63, minTime:023:10:12.295 [pool-1-thread-1] INFO MetricInterceptor 34 - methodName:/sampleService/say, current tps:86063, avgTime:0, maxTime:63, minTime:023:10:13.295 [pool-1-thread-1] INFO MetricInterceptor 34 - methodName:/sampleService/say, current tps:84305, avgTime:0, maxTime:63, minTime:0 DocumentsTODO
LicenseForest is released under the Apache License 2.0. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论