EbService generates kotlin code that enables a type-safe way of using the Vert.x EventBus. The generated code eliminates the need of guessing which types are required by EventBus consumers and which types are produced by them.
On top of that, the generated functions avoid unnecessary serialization and deserialization by making use of a special EventBus codec.
Imagine we have a service that can divide a double by another double.
We might model this service as follows:
interface DivisionService {
suspend fun divide(dividend: Double, divisor: Double): Division
sealed class Division {
data class Success(val quotient: Double) : Division()
data class Error(val message: String) : Division()
}
}
Next, we need to annotate this interface as follows:
@EventBusService
interface DivisionService
This will generate two things
- An implementation of this service (
DivisionServiceImpl
). This implementation forwards the parameters to subscribers of the generated properties. - An extension property to get the division requests:
Where
val Vertx.divideRequests: Flow<EventBusServiceRequest<DivisionRequest, Division>>
DivisionRequest
is a data class that wraps the two parameters.
This service is fully implemented in the example
module.
Add the JitPack repository to your build script and include the following dependencies:
implementation 'com.github.wowselim.eventbus-service:eventbus-service-core:<latestVersion>'
kapt 'com.github.wowselim.eventbus-service:eventbus-service-codegen:<latestVersion>'
The latest version can be found in the releases section.