Hessian framework profile and usage method
Hessian framework profile and usage method
Overview:
Hessian is a lightweight RPC (Remote Procedure Call) framework based on a binary protocol to achieve remote method calls.It can easily call cross -network methods in a distributed system, so that systems of different machines and different languages can communicate through remote methods.
The HESSIAN framework adopts a binary protocol. Compared with a text protocol -based transmission method such as SOAP, it is more efficient in network transmission, reducing the amount of data volume transmission and improving performance.In addition, hessian also supports cross -language calls that can be used in various languages such as Java, .NET, Python.
Hessian characteristics:
1. Simple and easy -to -use: One of the design goals of hessian is to provide a set of simple and easy -to -use APIs for users to make remote methods.
2. Cross -language support: Hessian supports calls across multiple languages, so that different systems can be seamlessly communicated.
3. High performance: Because hessian uses binary protocol transmission data, it is more efficient in network transmission, reducing bandwidth consumption, and improving system performance.
Instructions:
1. Introduction dependencies: Using hessian in the Java project, the corresponding hessian jar package needs to be introduced in the dependence of the project.For example, in the Maven project, the following dependencies can be added to the POM.XML file:
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.62</version>
</dependency>
2. Create server: To use hessian for remote method calls, you need to create a server first.The following is a simple example:
public class MyServiceImpl implements MyService {
public String greet(String name) {
return "Hello, " + name + "!";
}
}
public class Server {
public static void main(String[] args) throws IOException {
MyService service = new MyServiceImpl();
HessianServlet servlet = new HessianServlet(service, MyService.class);
HttpServer server = new HttpServer();
server.addContext("/rpc", servlet);
server.start();
}
}
In the above examples, `MyServiceIMPL` implements the` MyService` interface, and `myService` defines the remote method` greet`.The `Server` class creates a server, and register the` myServiceImpl` and `myService.class` to the hessianservlet, and the access path`/RPC` is bound.
3. Create a client: Next, you can create a client to call the server to call the server:
public class Client {
public static void main(String[] args) throws IOException {
HessianProxyFactory factory = new HessianProxyFactory();
String url = "http://localhost:8080/rpc";
MyService service = (MyService) factory.create(MyService.class, url);
String result = service.greet("World");
System.out.println(result);
}
}
In the above examples, `hessianproxyfactory` is a factory class used to create proxy objects, and the address and path of the server specifies the server.Using the `Factory.create` method to create an agent object of a` MyService` interface, and then you can call the remote method.
Summarize:
The HESSIAN framework is an easy -to -use, high -performance cross -language RPC framework.By introducing hessian to rely on and creating server and clients, it can easily realize remote methods calls between different systems.