Skip to content

Latest commit

 

History

History
104 lines (76 loc) · 2.3 KB

README.md

File metadata and controls

104 lines (76 loc) · 2.3 KB

Usagi

A kotlin multi-platform AMQP 0.9.1 client.

Warning Usagi is in Alpha, bugs may be ahead!

We are looking for contributors! If you are looking for a kotlin multiplatform AMQP client please consider opening PRs and Issues, it is very appreciated.

Installation

Requires Kotlin 1.8.20 and Java 8 if you're using the JVM artifact

🐘 Gradle

  • Latest Version: 1.0.0-rc.1
repositories {
    maven("https://maven.dimensional.fun/releases") // or /snapshots
}

dependencies {
    // common:
    implementation("fun.dimensional:usagi:{VERSION}")
}

Usage

Note
This API is not final, it may change in the future.

Create a Channel:

val connection = Usagi("amqp://localhost") {
    properties { connectionName = "my-service" }
}

val channel = connection.channels.create() 
    ?: error("Unable to create channel")

Using Exchanges & Queues

channel.exchange.declare { 
    exchange = "my-exchange" 
}

val queueName = channel.queue.declare()?.queue
    ?: error("Unable to declare queue")

channel.queue.bind {
    exchange = "my-exchange"
    queue = queueName
    routingKey = "my-routing-key"
}

Publishing Messages:

channel.basic.publish {
    data = "Hello, World!".encodeToByteArray()
    
    properties {
        contentType = "text/plain"
    }
    
    options {
        exchange = "my-exchange"
        routingKey = "my-routing-key"
    }
}

Consuming Messages:

val consumer = channel.basic.consume {
    queue = queueName
}

consumer.forEach { delivery ->
    println(delivery.data.decodeToString()) // >> 'Hello, World'
    delivery.ack(multiple = false)
}

Acknowledgements


Dimensional Fun