![License](https://img.shields.io/badge/license-Apache 2.0 -blue.svg?style=flat)
Simple wrapper for Vertx EventBus that allows organize type safety RPC communication.
- Type safety (it used Kryo library for object serialization)
- Asynchronous RPC calls by using
java.util.concurrent.CompletableFuture
- Server side exception handling
The library JARs are available on the releases page and at Maven Central. Latest snapshots of the library including snapshot builds of master are in the Sonatype Repository.
To use the Vert.x Typed RPC Services, add the following dependency to the dependencies section of your pom.xml
:
<dependency>
<groupId>com.xored.vertx</groupId>
<artifactId>vertx-typed-rpc</artifactId>
<version>1.0</version>
</dependency>
The example below describes a simple scenario of usage EventBus services:
- Specify RPC service interface
PersonService.java
that should be shared for client and server side:
package example;
import com.xored.vertx.typed.rpc.EventBusService;
import java.util.concurrent.CompletableFuture;
@EventBusService("person-service")
public interface PersonService {
CompletableFuture<Person> getPersonByName(String name);
}
- Add implementation class
PersonServiceImpl.java
for service
package example;
import java.util.concurrent.CompletableFuture;
public class PersonServiceImpl implements PersonService {
@Override
public CompletableFuture<Person> getPersonByName(String name) {
return CompletableFuture.completedFuture(new Person());
}
}
and register service with the following code:
EventBusServiceFactory.registerServer(eventBus, new PersonServiceImpl())
- On client side you need create proxy for service:
PersonService client = EventBusServiceFactory.createClient(eventBus, PersonService.class);
client.getPersonByName("test").thenAccept(person -> {
// person logic here
});