【RPC框架Burlap】Spring集成Burlap
编程技术  /  houtizong 发布于 3年前   73
Burlap和Hessian同属于codehaus的RPC调用框架,但是Burlap已经几年不更新,所以Spring在4.0里已经将Burlap的支持置为Deprecated,所以在选择RPC框架时,不应该考虑Burlap了。
这篇文章还是记录下Burlap的用法吧,主要是复制粘贴了Hessian与Spring集成一文,【RPC框架Hessian四】Hessian与Spring集成
Burlap和Hessian的共同点:
Burlap和Hessian的不同点:
在【RPC框架Hessian二】Hessian 对象序列化和反序列化一文中介绍了基于Hessian的RPC服务的实现步骤,在那里使用Hessian提供的API完成基于Hessian的RPC服务开发和客户端调用,本文使用Spring对Hessian的集成来实现Hessian的RPC调用。
|---Model
|--ComplexModel
|--Person
|--Point
|---Interface
|--IComplexModelService
|---Service Implementation
|--ComplexModelService
添加对Spring、Hessian和Spring Remoting的支持
<?xml version="1.0" encoding="UTF-8"?><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"> <parent> <artifactId>hessian.project</artifactId> <groupId>com.tom</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>learn.hessian.spring.integration</artifactId> <dependencies> <dependency> <groupId>com.caucho</groupId> <artifactId>hessian</artifactId> <version>4.0.38</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-remoting</artifactId> <version>2.0.8</version> </dependency> </dependencies> <build> <plugins> <!--jetty plugin to manage embedded jetty--> <!--No goal is specified--> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.7</version> <configuration> <connectors> <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> <port>8668</port> <maxIdleTime>30000</maxIdleTime> </connector> </connectors> <webAppSourceDirectory>${project.basedir}/web </webAppSourceDirectory> <contextPath>/web</contextPath> </configuration> </plugin> </plugins> </build></project>
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>hessian</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-hessian-server.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>hessian</servlet-name> <url-pattern>/hessian/*</url-pattern> </servlet-mapping></web-app>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!-- 服务暴露 --> <!--BurlapServiceExporter代替HessianServiceExporter--> <bean name="/complexModelService" class="org.springframework.remoting.caucho.BurlapServiceExporter"> <!-- 服务类 --> <property name="service"> <bean id="complexModelService" class="com.tom.hessian.server.ComplexModelService"/> </property> <property name="serviceInterface"> <value> com.tom.hessian.common.IComplexModelService </value> </property> </bean></beans>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!--远程对象代理工厂--> <!--BurlapProxyFactoryBean代替HessianProxyFactoryBean--> <bean name="complexModelService" class="org.springframework.remoting.caucho.BurlapProxyFactoryBean"> <!--BurlapProxyFactoryBean没有connectTimeout属性--> <property name="connectTimeout" value="60000"/> <property name="serviceUrl" value="http://localhost:8668/web/hessian/complexModelService"/> <property name="serviceInterface" value="com.tom.hessian.common.IComplexModelService"/> </bean></beans>
package com.tom.hessian.client;import com.tom.hessian.common.ComplexModel;import com.tom.hessian.common.IComplexModelService;import com.tom.hessian.common.Person;import com.tom.hessian.common.Point;import org.springframework.context.support.ClassPathXmlApplicationContext;import java.util.ArrayList;import java.util.Date;import java.util.List;public class ComplextModelServiceSpringTest { public static void main(String[] args) throws Exception { ComplexModel<Point> model = new ComplexModel<Point>(); model.setId(1); Person person = new Person(); person.setName("Tom"); person.setAge(86); person.setBirthDay(new Date()); person.setSensitiveInformation("This should be private over the wire"); model.setPerson(person); List<Point> points = new ArrayList<Point>(); Point point = new Point(); point.setX(3); point.setY(4); points.add(point); point = new Point(); point.setX(100); point.setY(100); points.add(point); model.setPoints(points); //远程方法调用 ClassPathXmlApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext-hessian-client.xml"); IComplexModelService service = cxt.getBean("complexModelService", IComplexModelService.class); service.save(model); model = service.read(model.getId()); List<Point> points1 = model.getPoints(); for(Point elem : points1) { System.out.println(elem.getX() + "\t" + elem.getY()); } }}
启动Jetty Server,然后运行上面的客户端代码,可以正常执行
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接