https://github.com/megaprog/vertx-hessian
The approach to export Hessian service through Vert.x Verticle
https://github.com/megaprog/vertx-hessian
Last synced: 8 months ago
JSON representation
The approach to export Hessian service through Vert.x Verticle
- Host: GitHub
- URL: https://github.com/megaprog/vertx-hessian
- Owner: Megaprog
- Created: 2015-10-31T09:39:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-31T09:49:35.000Z (over 10 years ago)
- Last Synced: 2025-08-13T05:39:27.399Z (10 months ago)
- Language: Java
- Size: 129 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Asynchronous Hessian
The approach to export [Hessian](http://hessian.caucho.com/) service through [Vert.x](http://vertx.io/) Verticle
## How to get it?
You can use it as a maven dependency:
```xml
org.jmmo
vertx-hessian
1.0
```
Or download the latest build at:
https://github.com/megaprog/vertx-hessian/releases
## How to use it?
Create client interface:
```java
public interface HessianServiceInterface {
Integer synchronousCall();
Integer asynchronousCall();
}
```
Create server interface with same method signatures as in client one but asynchronous methods must return CompletableFuture:
```java
public interface HessianServiceInterfaceAsync {
Integer synchronousCall();
CompletableFuture asynchronousCall();
}
```
Implement server asynchronous interface:
```java
public class HessianServiceInterfaceAsyncImpl implements HessianServiceInterfaceAsync {
private static final Logger log = Logger.getLogger(HessianServiceInterfaceAsyncImpl.class.getName());
@Override
public Integer synchronousCall() {
log.info(() -> "Calling from http processing thread");
return 1;
}
@Override
public CompletableFuture asynchronousCall() {
return CompletableFuture.supplyAsync(() -> {
log.info(() -> "Calling from ForkJoinPool thread");
return 2;
});
}
}
```
Server:
```java
public class ExampleHessianVerticleServer extends AbstractHessianVerticleServer {
@Override
public Class> getApiClass() {
return HessianServiceInterfaceAsync.class;
}
@Override
protected Object createService() {
return new HessianServiceInterfaceAsyncImpl();
}
}
```
Client:
```java
public class Client {
protected static final String SERVICE_URL = "http://localhost:8080";
public static void main(String[] args) {
final HessianServiceInterface hessianService = hessianService();
System.out.println("synchronous method calling result is " + hessianService.synchronousCall());
System.out.println("asynchronous method calling result is " + hessianService.asynchronousCall());
}
protected static HessianServiceInterface hessianService() {
try {
return (HessianServiceInterface) new HessianProxyFactory().create(HessianServiceInterface.class, SERVICE_URL);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}
```
See more at client-server example:
https://github.com/Megaprog/vertx-hessian/tree/master/example