amqp-connector is a RabbitMQ/AMQP client library relying on the official RabbitMQ client for Java.
Add the amqp-connector dependency to your Gradle build script
implementation("no.dossier.libraries:amqp-connector:0.1.0")
Create an instance of the connector using dedicated Kotlin DSL and start publishing and/or consuming messages
class ExampleResource {
val connector = connector(role = PublisherAndConsumer) {
connectionString = "amqp://guest:guest@localhost:5672/"
clientName = "sample-app"
consumer(::sampleProcessingFunction) {
workersCoroutineScope = CoroutineScope(Dispatchers.Default)
exchange { name = "some-ref-data" }
bindingKey = Custom("refdata.*.user.#")
}
}
val publisher = connector.publisher {
exchange { name = "somedata-exchange" }
routingKey = "somedata.cool.special"
}
suspend fun sampleProcessingFunction(message: AmqpInboundMessage<String>): Outcome<AmqpConsumingError, Unit> {
println(message.payload)
return Success(Unit)
}
suspend fun sendSamplePublication(request: String): Outcome<AmqpPublishingError, Unit> =
publisher(AmqpOutboudMessage(request))
}
See the internal Javadoc for more details
See LICENSE
Any contributions and improvements are very welcome. Feel free to submit any pull-requests.