add PublicEventService
This commit is contained in:
25
src/main/kotlin/ltd/hlaeja/service/PublicEventService.kt
Normal file
25
src/main/kotlin/ltd/hlaeja/service/PublicEventService.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package ltd.hlaeja.service
|
||||
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import ltd.hlaeja.entity.AccountEntity
|
||||
import ltd.hlaeja.library.accountRegistry.event.AccountMessage
|
||||
import org.springframework.kafka.core.KafkaTemplate
|
||||
import org.springframework.stereotype.Service
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
@Service
|
||||
class PublicEventService(
|
||||
private val kafkaTemplate: KafkaTemplate<String, AccountMessage>,
|
||||
) {
|
||||
|
||||
fun updateAccount(
|
||||
account: AccountEntity,
|
||||
changes: List<String>,
|
||||
): Mono<AccountEntity> = Mono
|
||||
.fromFuture(kafkaTemplate.send("account", "change", AccountMessage(account.id!!, changes)))
|
||||
.doOnSuccess { log.trace { "Sent Kafka created event for user ${account.id}" } }
|
||||
.doOnError { e -> log.error(e) { "Failed to send Kafka event" } }
|
||||
.thenReturn(account)
|
||||
}
|
||||
Reference in New Issue
Block a user