package dp.kotul.starter.messaging.service

import dp.kotul.starter.messaging.model.BaseMessage
import org.slf4j.Logger
import org.springframework.amqp.rabbit.core.RabbitTemplate
import org.springframework.stereotype.Service

interface Rabbit {
    fun distributeMessage(exchange: String, topic: String, message: BaseMessage)
}

@Service
class RabbitImpl(val rabbitTemplate: RabbitTemplate, val log: Logger) : Rabbit {

    override fun distributeMessage(exchange: String, topic: String, message: BaseMessage) {
        rabbitTemplate.convertAndSend(exchange, topic, message) {
            return@convertAndSend it
        }

        log.debug("Message: $message for topic: $topic sent to exchange: $exchange")
    }
}
