All Downloads are FREE. Search and download functionalities are using the official Maven repository.

.messaging_rabbitmq.2.0.14.source-code.RabbitMqAdapter.kt Maven / Gradle / Ivy

package com.hexagonkt.messaging.rabbitmq

import com.hexagonkt.messaging.Message
import com.hexagonkt.messaging.MessagingPort
import com.hexagonkt.serialization.serialize
import java.net.URI
import kotlin.reflect.KClass

class RabbitMqAdapter(url: String = "amqp://guest:guest@localhost") : MessagingPort {
    private companion object {
        private const val exchange = "messages"
    }

    private val client by lazy { RabbitMqClient(URI(url)) }

    init {
        client.bindExchange(exchange, "topic", "*.*.*", "event_pool")
    }

    override fun  consume(type: KClass, address: String, consumer: (T) -> Unit) {
        client.consume(exchange, address, type) { consumer(it) }
    }

    override fun publish(message: Message, address: String) {
        client.publish(exchange, address, message.serialize())
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy