Big refactoring #77

Merged
flecomte merged 166 commits from refactoring-component-and-immutable into master 2021-03-24 19:06:07 +01:00
4 changed files with 7 additions and 11 deletions
Showing only changes of commit dd6433306d - Show all commits

View File

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

View File

@@ -54,9 +54,6 @@ import fr.dcproject.component.opinion.OpinionRepositoryArticle as OpinionArticle
@KtorExperimentalAPI @KtorExperimentalAPI
val KoinModule = module { val KoinModule = module {
single { Configuration }
// SQL connection // SQL connection
single { single {
Connection( Connection(
@@ -152,7 +149,7 @@ val KoinModule = module {
// Used to send a connexion link by email // Used to send a connexion link by email
single { PasswordlessAuth(get<Mailer>(), Configuration.domain, get()) } 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()) } 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.Consumer
import com.rabbitmq.client.DefaultConsumer import com.rabbitmq.client.DefaultConsumer
import com.rabbitmq.client.Envelope import com.rabbitmq.client.Envelope
import fr.dcproject.application.Configuration
import fr.dcproject.common.entity.TargetRef import fr.dcproject.common.entity.TargetRef
import fr.dcproject.component.article.ArticleForView import fr.dcproject.component.article.ArticleForView
import fr.dcproject.component.citizen.CitizenRef import fr.dcproject.component.citizen.CitizenRef
@@ -46,13 +45,13 @@ class EventNotification(
private val redis: RedisAsyncCommands<String, String>, private val redis: RedisAsyncCommands<String, String>,
private val followRepo: FollowArticleRepository, private val followRepo: FollowArticleRepository,
private val publisher: Publisher, 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) private val logger: Logger = LoggerFactory.getLogger(Publisher::class.qualifiedName)
fun config() { fun config() {
/* Config Rabbit */ /* Config Rabbit */
val exchangeName = Configuration.exchangeNotificationName
rabbitFactory.newConnection().use { connection -> rabbitFactory.newConnection().use { connection ->
connection.createChannel().use { channel -> connection.createChannel().use { channel ->
channel.queueDeclare("push", true, false, false, null) 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.fasterxml.jackson.databind.ObjectMapper
import com.rabbitmq.client.ConnectionFactory import com.rabbitmq.client.ConnectionFactory
import fr.dcproject.application.Configuration
import fr.dcproject.event.EntityEvent import fr.dcproject.event.EntityEvent
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@@ -13,13 +12,14 @@ import org.slf4j.LoggerFactory
class Publisher( class Publisher(
private val mapper: ObjectMapper, private val mapper: ObjectMapper,
private val factory: ConnectionFactory, 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 { fun <T : EntityEvent> publish(it: T): Job {
return GlobalScope.launch { return GlobalScope.launch {
factory.newConnection().use { connection -> factory.newConnection().use { connection ->
connection.createChannel().use { channel -> 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}") logger.debug("Publish message ${it.target.id}")
} }
} }