发表于: 2017-05-27 18:54:34
1 1275
今天完成的事情:
部署两台Service,在WEB中随机访问任意一台Service。
我是直接在main方法中调用的util类的random方法取1,2,然后通过for循环多次随机调用
public static void main (String [] args)throws NotBoundException,
java.net.MalformedURLException,
RemoteException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
ClassPathXmlApplicationContext context2 = new ClassPathXmlApplicationContext("spring2.xml");
StudentService studentService = (StudentService) context.getBean("StudentService");
StudentService studentService2 = (StudentService) context2.getBean("StudentService2");
// System.out.print(studentService.OP());
// System.out.print(studentService2.OP());
for (int i=1;i<10;i++){
Random rd = new Random();
int yh = rd.nextInt(2)+1;
if (yh==1){
System.out.print(studentService.OP());
}
else {
System.out.print(studentService2.OP());
}
}
}
}
明天计划的事情:
尝试部署到服务器上通过nginx负载均衡随机访问
遇到的问题:
今天同时启动两个服务端的时候 总有一个连接不上,找了半天没找到问题在哪,因为服务端代码都是一样的只是端口不同,后来看了半天 师兄点拨了一句,说服务名也要改,因为我一直认为,先通端口再找name
<bean id="StudentService2" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://localhost:7777/StudentService"></property>
<property name="serviceInterface" value="com.jnshu.service.StudentService"></property>
.......后来改好后成功了....循环十次随机调用111121212...
收获:
算是理解了rmi的一点点皮毛吧....
评论