Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trendyol/kediatr
Mediator implementation in Kotlin with native coroutine support
https://github.com/trendyol/kediatr
coroutines cqrs cqs inprocess-bus koin kotlin mediator mediator-pattern quarkus spring-boot
Last synced: 8 days ago
JSON representation
Mediator implementation in Kotlin with native coroutine support
- Host: GitHub
- URL: https://github.com/trendyol/kediatr
- Owner: Trendyol
- License: mit
- Created: 2019-09-10T16:22:47.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-30T08:57:42.000Z (9 days ago)
- Last Synced: 2024-10-30T09:26:09.705Z (9 days ago)
- Topics: coroutines, cqrs, cqs, inprocess-bus, koin, kotlin, mediator, mediator-pattern, quarkus, spring-boot
- Language: Kotlin
- Homepage: https://trendyol.github.io/kediatR/
- Size: 3.1 MB
- Stars: 178
- Watchers: 19
- Forks: 24
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# kediatR [![codecov](https://codecov.io/gh/trendyol/kediatr/branch/main/graph/badge.svg)](https://codecov.io/gh/trendyol/kediatr)
Mediator implementation in kotlin with native coroutine support. Supports Spring-Boot, Quarkus and Koin dependency
providers.> [!TIP]
> "kedi" in Turkish means cat 🐱 and kediatR rhymes with the C# equivalent library [mediatR](https://github.com/jbogard/MediatR) :)Documentation is available at [https://trendyol.github.io/kediatR/](https://trendyol.github.io/kediatR/)
## Show me the code
```kotlin
class PingCommand : Command // or
class PingQuery : Query // or
class PingNotification : Notification
class PingCommandHandler : CommandHandler {
override suspend fun handle(command: PingCommand) {
println("Pong!")
}
}
class PingQueryHandler : QueryHandler {
override suspend fun handle(query: PingQuery): String {
return "Pong!"
}
}class PingNotificationHandler : NotificationHandler {
override suspend fun handle(notification: PingNotification) {
println("Pong!")
}
}class MeasurePipelineBehaviour : PipelineBehaviour {
override val order: Int = 0
override suspend fun handle(
request: TRequest,
next: RequestHandlerDelegate
): TResponse {
val start = System.currentTimeMillis()
val response = next(request)
val end = System.currentTimeMillis()
println("Request ${request::class.simpleName} took ${end - start} ms")
return response
}
}val mediator = // create mediator instance in-memory or with dependency injection, take a look at the documentation
mediator.send(PingCommand()) // 1..1
mediator.send(PingQuery()) // 1..1
mediator.send(PingNotification()) // 0..N
```