1.dubbon 基本使用
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><packaging>war</packaging><artifactId>dubbo-server</artifactId><properties><spring.version>5.1.9.RELEASE</spring.version><zookeeper.version>4.0.0</zookeeper.version><dubbo.version>2.7.5</dubbo.version></properties><dependencies><!-- spring的坐标 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><!-- springmvc的坐标 --><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-recipes</artifactId><version>${zookeeper.version}</version></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>${zookeeper.version}</version></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo</artifactId><version>${dubbo.version}</version></dependency><dependency><groupId>com.example.demo</groupId><artifactId>dubbo-interface</artifactId><version>1.0-SNAPSHOT</version><scope>compile</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><configuration><path>/</path><port>8093</port></configuration></plugin></plugins></build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-4.0.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://dubbo.apache.org/schema/dubbohttp://dubbo.apache.org/schema/dubbo/dubbo.xsd"><mvc:annotation-driven/><dubbo:protocol port="20884"></dubbo:protocol><dubbo:application name="dubbo-service"/><dubbo:registry address="zookeeper://127.0.0.1:2181"></dubbo:registry><dubbo:annotation package="com.example.demo.service.impl"/><dubbo:metadata-report address="zookeeper://127.0.0.1:2181"></dubbo:metadata-report>
</beans>
@Service(weight = 500)
public class UserServiceImpl implements UserService {public String sayHello() {return "hello dubbon client 3";}
}
2.dubbon 的高级特性
这个也不算啥高级特性,图形用户界面最没水平
负载均衡
负载均衡
Random 随机访问
RoundRoubin 轮询按权重
LeastOne 根据活跃度调用