Remove Configuration object to koin

This commit is contained in:
2021-01-23 22:47:02 +01:00
parent bfc0b7e796
commit dd6433306d
4 changed files with 7 additions and 11 deletions

View File

@@ -104,7 +104,7 @@ fun Application.module(env: Env = PROD) {
}
install(EventSubscriber) {
EventNotification(this, get(), get(), get(), get(), get()).config()
EventNotification(this, get(), get(), get(), get(), get(), Configuration.exchangeNotificationName).config()
}
install(Authentication, jwtInstallation(get()))

View File

@@ -54,9 +54,6 @@ import fr.dcproject.component.opinion.OpinionRepositoryArticle as OpinionArticle
@KtorExperimentalAPI
val KoinModule = module {
single { Configuration }
// SQL connection
single {
Connection(
@@ -152,7 +149,7 @@ val KoinModule = module {
// Used to send a connexion link by email
single { PasswordlessAuth(get<Mailer>(), Configuration.domain, get()) }
single { Publisher(get(), get()) }
single { Publisher(get(), get(), exchangeName = Configuration.exchangeNotificationName) }
single { NotificationEmailSender(get<Mailer>(), Configuration.domain, get(), get()) }
}

View File

@@ -6,7 +6,6 @@ import com.rabbitmq.client.ConnectionFactory
import com.rabbitmq.client.Consumer
import com.rabbitmq.client.DefaultConsumer
import com.rabbitmq.client.Envelope
import fr.dcproject.application.Configuration
import fr.dcproject.common.entity.TargetRef
import fr.dcproject.component.article.ArticleForView
import fr.dcproject.component.citizen.CitizenRef
@@ -46,13 +45,13 @@ class EventNotification(
private val redis: RedisAsyncCommands<String, String>,
private val followRepo: FollowArticleRepository,
private val publisher: Publisher,
private val notificationEmailSender: NotificationEmailSender
private val notificationEmailSender: NotificationEmailSender,
private val exchangeName: String,
) {
private val logger: Logger = LoggerFactory.getLogger(Publisher::class.qualifiedName)
fun config() {
/* Config Rabbit */
val exchangeName = Configuration.exchangeNotificationName
rabbitFactory.newConnection().use { connection ->
connection.createChannel().use { channel ->
channel.queueDeclare("push", true, false, false, null)

View File

@@ -2,7 +2,6 @@ package fr.dcproject.event.publisher
import com.fasterxml.jackson.databind.ObjectMapper
import com.rabbitmq.client.ConnectionFactory
import fr.dcproject.application.Configuration
import fr.dcproject.event.EntityEvent
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
@@ -13,13 +12,14 @@ import org.slf4j.LoggerFactory
class Publisher(
private val mapper: ObjectMapper,
private val factory: ConnectionFactory,
private val logger: Logger = LoggerFactory.getLogger(Publisher::class.qualifiedName)
private val logger: Logger = LoggerFactory.getLogger(Publisher::class.qualifiedName),
private val exchangeName: String,
) {
fun <T : EntityEvent> publish(it: T): Job {
return GlobalScope.launch {
factory.newConnection().use { connection ->
connection.createChannel().use { channel ->
channel.basicPublish(Configuration.exchangeNotificationName, "", null, it.serialize().toByteArray())
channel.basicPublish(exchangeName, "", null, it.serialize().toByteArray())
logger.debug("Publish message ${it.target.id}")
}
}