标签:one artifact echo bin bsp const for bat 负载均衡
cd /usr/local/zookeeper/zookeeper-3.4.10/conf cp zoo_sample.cfg zoo.cfg
mkdir -p /usr/local/zkCluster
cp /usr/local/zookeeper/zookeeper-3.4.10 /usr/local/zkCluster/zk1 -rf
mkdir -p /usr/local/zkCluster/zk1/data
cd /usr/local/zkCluster cp -rf zk1 zk2 cp -rf zk1 zk3
#!/bin/bash case "$1" in start) echo ‘Starting zkCluster...‘ /usr/local/zkcluster/zk1/bin/zkServer.sh start /usr/local/zkcluster/zk2/bin/zkServer.sh start /usr/local/zkcluster/zk3/bin/zkServer.sh start ;; stop) echo ‘Stopping zkCluster...‘ /usr/local/zkcluster/zk1/bin/zkServer.sh stop /usr/local/zkcluster/zk2/bin/zkServer.sh stop /usr/local/zkcluster/zk3/bin/zkServer.sh stop ;; status) /usr/local/zkcluster/zk1/bin/zkServer.sh status /usr/local/zkcluster/zk2/bin/zkServer.sh status /usr/local/zkcluster/zk3/bin/zkServer.sh status ;; restart|force-reload) echo ‘Restarting zkCluster...‘ ${0} stop ${0} start ;; *) esac
./zkCluster.sh restart
package cn.gzsxt.dubbo.pojo; import java.io.Serializable; public class User implements Serializable{ /** * */ private static final long serialVersionUID = 4498814071761004317L; private Integer id; private String name; private String pwd; public User() { super(); // TODO Auto-generated constructor stub } public User(int id, String name, String pwd) { this.id = id; this.name = name; this.pwd = pwd; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } }
package cn.gzsxt.dubbo.pojo; import java.io.Serializable; public class User implements Serializable{ /** * */ private static final long serialVersionUID = 4498814071761004317L; private Integer id; private String name; private String pwd; public User() { super(); // TODO Auto-generated constructor stub } public User(int id, String name, String pwd) { this.id = id; this.name = name; this.pwd = pwd; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } }
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.gzsxt.dubbo</groupId> <artifactId>dubbo-provider</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <!-- 导入dubbo-server服务接口 --> <dependency> <groupId>cn.gzsxt.dubbo</groupId> <artifactId>dubbo-server</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <!-- dubbo采用spring配置方式,所以需要导入spring容器依赖 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.3.RELEASE</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.4</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <!-- 排除传递spring依赖 --> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.3.3</version> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>8081</port> <path>/</path> </configuration> </plugin> </plugins> </build> </project>
package cn.gzsxt.dubbo.service.impl; import java.util.ArrayList; import java.util.List; import cn.gzsxt.dubbo.pojo.User; import cn.gzsxt.dubbo.service.UserService; /** * UserService服务的实现类 * @author lyq * */ public class UserServiceImpl implements UserService{ @Override public List<User> getAllUsers() { List<User> uList = new ArrayList<>(); User user = null; //模拟查询数据库 for(int i =0;i<5;i++){ user = new User(i,"zs"+i,"gzsxt"+i); uList.add(user); } return uList; } }
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 提供方应用信息,用于计算依赖关系 --> <dubbo:application name="dubbo-provider" /> <!-- 这里使用的注册中心是zookeeper --> <dubbo:registry protocol="zookeeper" address="192.168.56.3:2181,192.168.56.3:2182,192.168.56.3:2183" /> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 将具体的实现类加入到Spring容器中 --> <bean id="userServiceImpl" class="cn.gzsxt.dubbo.service.impl.UserServiceImpl" /> <!-- 将服务接口暴露到dubbo中 --> <dubbo:service interface="cn.gzsxt.dubbo.service.UserService" ref="userServiceImpl" /> </beans>
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>dubbo-provider</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:dubbo/dubbo-*.xml</param-value> </context-param> <!--Spring的ApplicationContext 载入 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.gzsxt.dubbo</groupId> <artifactId>dubbo-consumer</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <!-- 导入dubbo-server服务接口 --> <dependency> <groupId>cn.gzsxt.dubbo</groupId> <artifactId>dubbo-server</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <!-- dubbo采用spring配置方式,所以需要导入spring容器依赖 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.3.RELEASE</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.4</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <!-- 排除传递spring依赖 --> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.3.3</version> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency> </dependencies> </project>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 提供方应用信息,用于计算依赖关系 --> <dubbo:application name="dubbo-consumer" /> <!-- 这里使用的注册中心是zookeeper --> <dubbo:registry protocol="zookeeper" address="192.168.56.3:2181,192.168.56.3:2182,192.168.56.3:2183" /> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 引用dubbo中的服务 --> <dubbo:reference interface="cn.gzsxt.dubbo.service.UserService" id="userService" /> </beans>
package cn.gzsxt.dubbo.test; import java.util.List; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import cn.gzsxt.dubbo.pojo.User; import cn.gzsxt.dubbo.service.UserService; public class TestConsumer { @Test public void testConsumer(){ //1.读取配置文件,加载容器 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:dubbo/dubbo-consumer.xml"); //2.获取bean对象 UserService userService = context.getBean("userService", UserService.class); //3.调用方法 List<User> users = userService.getAllUsers(); System.out.println(users); } }
mkdir -p /usr/local/dubbo
|
tar zxvf dubbo-monitor-simple-2.5.3-assembly.tar.gz -C /usr/local/dubbo
|
cd /usr/local/dubbo/dubbo-monitor-simple-2.5.3/conf
|
cd /usr/local/dubbo/dubbo-monitor-simple-2.5.3/bin/
|
tar zxvf apache-tomcat-7.0.68.tar.gz -C /usr/local/dubbo
rm /usr/local/dubbo/apache-tomcat-7.0.68/webapps/ROOT/* -rf
|
unzip dubbo-admin-2.5.4.war -d /usr/local/dubbo/ tomcat-7.0.68/webaaps/Root
|
cd /usr/local/dubbo/apache-tomcat-7.0.68/webapps/ROOT/WEB-INF
|
cd /usr/local/dubbo/apache-tomcat-7.0.68/bin && ./startup.sh
|
|
<!-- 导入spring-test的依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
|
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:dubbo/dubbo-consumer.xml")
public class TestConsumer {
@Reference
private UserService userService;
@Test
public void testConsumer(){
List<User> users = userService.getAllUsers();
System.out.println(users);
}
}
|
标签:one artifact echo bin bsp const for bat 负载均衡
原文地址:https://www.cnblogs.com/aknife/p/11372368.html