This repository contains RabbitMQ tutorials implemented using Kourier, a pure Kotlin multiplatform AMQP client.
These tutorials demonstrate the core concepts of RabbitMQ using Kotlin and the Kourier AMQP client library. All examples work on JVM, macOS (ARM64), Linux (x64), and Windows (x64) platforms through Kotlin Multiplatform.
- RabbitMQ server running on localhost (default port 5672)
- Kotlin 2.1.21
- Gradle
./gradlew buildThe simplest thing that does something - sending and receiving messages from a named queue.
Functions:
send()- Sends "Hello World!" message to the queuereceive()- Receives and prints messages from the queue
Distributing time-consuming tasks among multiple workers.
Functions:
newTask(message)- Sends a task to the work queue (dots represent work time)worker(workerName)- Processes tasks with fair dispatch and manual acknowledgment
Key concepts:
- Message durability
- Fair dispatch with
basicQos - Manual acknowledgments
Sending messages to many consumers at once using fanout exchanges.
Functions:
emitLog(message)- Publishes log messages to all subscribersreceiveLogs(subscriberName)- Subscribes to all log messages
Key concepts:
- Fanout exchanges
- Temporary queues
- Broadcasting messages
Receiving messages selectively using direct exchanges and routing keys.
Functions:
emitLogDirect(severity, message)- Publishes log with specific severityreceiveLogsDirect(subscriberName, severities)- Subscribes to specific severities
Key concepts:
- Direct exchanges
- Routing keys
- Multiple bindings per queue
Receiving messages based on patterns using topic exchanges.
Functions:
emitLogTopic(routingKey, message)- Publishes with topic routing keyreceiveLogsTopic(subscriberName, bindingKeys)- Subscribes using patterns
Key concepts:
- Topic exchanges
- Wildcard patterns (
*= one word,#= zero or more words) - Pattern-based routing
Request/reply pattern for remote procedure calls.
Functions:
rpcServer()- Processes Fibonacci number requestsrpcClient(n)- Sends RPC request and waits for response
Key concepts:
- Callback queues
- Correlation IDs
- Reply-to pattern
These tutorials are designed as library functions. You can call them from your own code or tests. For example:
import kotlinx.coroutines.runBlocking
fun main() = runBlocking {
// Example: Run work queue tutorial
launch { worker(this, "Worker-1") }
launch { worker(this, "Worker-2") }
delay(1000) // Give workers time to start
newTask(this, "Task with work...")
}For detailed explanations of each tutorial, see the Kourier documentation.