发表于: 2017-04-04 22:24:40

6 1446


一.今天完成的

1.解决昨天的问题,将原有的Spring RMI更改为Tuscany的RMI,WEB端更改为Tuscany的调用方式。

2.

  • 部署两台Service,在WEB中随机访问任意一台Service。
  • 部署两台WEB,通过Nginx配置两台WEB随机访问,两台WEB可以随机访问两台Service。

二.明天计划

1.熟悉复盘项目

三.今天的收获

1.昨天发布服务报错的问题是jar包冲突的原因,因为Tuscany2.0与spring3.1以上的版本会有冲突,将spring版本改为3.0.5后就不再报错

2.客户端如何调用

和任务8几乎一毛一样,知识把端口号改一下

<?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:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="com.jnshu" />

<bean id="studentService2" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" scope="prototype">
<property name="serviceUrl" value="//localhost:8082/StudentService"/>
<property name="serviceInterface" value="com.jnshu.service.StudentService"/>
</bean>

<bean id="studentService1" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" scope="prototype">
<property name="serviceUrl" value="//localhost:8081/StudentService"></property>
<property name="serviceInterface" value="com.jnshu.service.StudentService"/>
</bean>

</beans>

controller类也跟task8一毛一样,不需要改任何东西

@Controller
@RequestMapping("/student")
public class StudentController {
private static  Logger logger = Logger.getLogger(StudentController.class);
private ApplicationContext context = null;
@RequestMapping( value = "/{id}" ,method = RequestMethod.GET)
public String getStudentById(HttpServletRequest request,HttpServletResponse response
,ModelMap modelMap, @PathVariable Long id){
context = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
int flag = Math.random() > 0.5 ? 1 : 0;
System.out.println("产生的随机数是:" + flag);
Student student = null;
try {
switch (flag) {
case 1:
StudentService studentService1 = (StudentService) context.getBean("studentService1");
System.out.println("第一层访问service1");
student = studentService1.select(id);
break;
default:
StudentService studentService2 = (StudentService) context.getBean("studentService2");
System.out.println("第一层访问service2");
student = studentService2.select(id);
break;}
} catch (Exception e1) {
switch (flag) {
case 1:
StudentService studentService2 = (StudentService) context.getBean("studentService2");
System.out.println("第一层访问失败,转为第二层访问service2");
student = studentService2.select(id);
break;
default:
StudentService studentService1 = (StudentService) context.getBean("studentService1");
System.out.println("第一层访问失败,转为第二层访问service1");
student = studentService1.select(id);
break;}
}
modelMap.addAttribute("student",student);
return "student";
}

}

接下来是部署两台service,部署两台web,套路跟task8一毛一样

四.遇到的问题

1.今天跟[外门弟子] 不想再懒了 聊到关于服务端部署的问题,我们有不同的想法,

a.他的思路是服务端和客户端完全分离,就是服务端和客户端口都发布到tomcat或者jetty服务器上

这样的话,按照任务要求两台web和两台service一共要发布到四台服务器

然后nginx负载四台服务器

b.我的思路是服务端和客户端没有完全分离,在同一个聚合项目里面,而服务端是通过一个启动类来发布的,不需要发布到tomcat服务器上,客户端就能远程调用,

如果按照任务要求两台web和两台service,只需要将两台web部署到服务器上即可,不过先要手动将两台service启动发布,

因为服务端启动发布类是主方法,所以即使服务端发布到服务器上,也是可以直接手动运行主方法的

这是两种不同的思路


返回列表 返回列表
评论

    分享到