A lightweight Kotlinx Serialization–powered event bus with pluggable drivers (Redis, in-memory, etc.), annotation-based listeners, and coroutine support.
repositories {
mavenCentral()
}
dependencies {
implementation("dev.invalidjoker:bell:<latest-version>")
}All events extend Notification and use Kotlinx Serialization:
import kotlinx.serialization.Serializable
@Serializable
data class TestNotification(
val foo: String,
val bar: String,
) : Notification(
channel = "test",
type = "notification"
)class MyListener {
@NotificationListener
suspend fun onTestNotification(event: TestNotification) {
println("Received via annotation:")
println(" foo = ${event.foo}")
println(" bar = ${event.bar}")
}
}engine.onEvent<TestNotification> { event ->
println("Received inline:")
println(" foo = ${event.foo}")
println(" bar = ${event.bar}")
}Inline listeners work for any event type and do not require annotations.
Bell supports different backends through pluggable drivers.
import de.joker.bell.NotificationEngine
import de.joker.bell.drivers.RedisDriver
import redis.clients.jedis.JedisPool
fun main() {
val jedis = JedisPool("localhost", 6379)
val engine = NotificationEngine(
RedisDriver(jedis, "notifications")
)
// Connect to Redis
engine.connect()
// Register annotated listener
engine.registerAnnotated(MyListener())
// Register inline listener
engine.onEvent<TestNotification> { event ->
println("Inline: $event")
}
// Send an event
engine.send(TestNotification("Hello", "World"))
}This driver sends notifications only inside the same JVM, great for tests or local development.
import de.joker.bell.NotificationEngine
import de.joker.bell.drivers.LocalDriver
fun main() {
val engine = NotificationEngine(LocalDriver())
// Connect
engine.connect()
// Register inline listener
engine.onEvent<TestNotification> { event ->
println("Local received:")
println(" foo = ${event.foo}")
println(" bar = ${event.bar}")
}
// Register annotated listener (optional)
engine.registerAnnotated(MyListener())
// Send event
engine.send(TestNotification("Local", "Driver"))
}