All Projects → viartemev → the-white-rabbit

viartemev / the-white-rabbit

Licence: MIT license
The White Rabbit is an asynchronous RabbitMQ (AMQP) client based on Kotlin coroutines

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to the-white-rabbit

Ktx
LibKTX: Kotlin extensions for LibGDX games and applications
Stars: ✭ 913 (+914.44%)
Mutual labels:  coroutines, kotlin-coroutines
Androidcoroutinesplayground
Android Coroutines Playground
Stars: ✭ 119 (+32.22%)
Mutual labels:  coroutines, kotlin-coroutines
Eyepetizer
🔥基于 Kotlin 语言仿写「开眼 Eyepetizer」的一个短视频 Android 客户端项目,采用 Jetpack + 协程实现的 MVVM 架构。
Stars: ✭ 988 (+997.78%)
Mutual labels:  coroutines, kotlin-coroutines
Kotlin Coroutines Retrofit
Kotlin Coroutines await() extension for Retrofit Call
Stars: ✭ 812 (+802.22%)
Mutual labels:  coroutines, kotlin-coroutines
fs2-rabbit
🐰 RabbitMQ stream-based client built on top of Fs2
Stars: ✭ 143 (+58.89%)
Mutual labels:  amqp, rabbitmq-client
Myweatherkotlinflow
Android app that shows weather at your current location or any custom location you specify. Uses Kotlin Flow for data streaming and coroutines for asynchronous work. Also leverages Room, navigation component, Viewmodel and Livedata Jetpack components with MVVM presentation layer architecture. Dagger 2 with Dagger android for dependency injection
Stars: ✭ 23 (-74.44%)
Mutual labels:  coroutines, kotlin-coroutines
Kotlin Coroutines Android
Useful extensions for coroutines. AutoDispose + MainScope
Stars: ✭ 77 (-14.44%)
Mutual labels:  coroutines, kotlin-coroutines
Uniflow Kt
Uniflow 🦄 - Simple Unidirectional Data Flow for Android & Kotlin, using Kotlin coroutines and open to functional programming
Stars: ✭ 414 (+360%)
Mutual labels:  coroutines, kotlin-coroutines
Android Clean Arch Coroutines Koin
Implemented by Clean Architecture, MVVM, Koin, Coroutines, Moshi, Mockk, LiveData & DataBinding
Stars: ✭ 173 (+92.22%)
Mutual labels:  coroutines, kotlin-coroutines
Splitties
A collection of hand-crafted extensions for your Kotlin projects.
Stars: ✭ 1,945 (+2061.11%)
Mutual labels:  coroutines, kotlin-coroutines
Korge
KorGE Game Engine. Multiplatform Kotlin Game Engine
Stars: ✭ 780 (+766.67%)
Mutual labels:  coroutines, kotlin-coroutines
nabbitmq
Node.js library for interacting with RabbitMQ based on RxJS streams
Stars: ✭ 20 (-77.78%)
Mutual labels:  amqp, rabbitmq-client
Coil
Image loading for Android backed by Kotlin Coroutines.
Stars: ✭ 7,469 (+8198.89%)
Mutual labels:  coroutines, kotlin-coroutines
Enqueue Dev
Message Queue, Job Queue, Broadcasting, WebSockets packages for PHP, Symfony, Laravel, Magento. DEVELOPMENT REPOSITORY - provided by Forma-Pro
Stars: ✭ 1,977 (+2096.67%)
Mutual labels:  amqp, rabbitmq-client
Kotlin Coroutines Android Examples
Learn Kotlin Coroutines for Android by Examples. Learn how to use Kotlin Coroutines for Android App Development.
Stars: ✭ 572 (+535.56%)
Mutual labels:  coroutines, kotlin-coroutines
Paperplane
📚 PaperPlane - An Android reading app, including articles from Zhihu Daily, Guokr Handpick and Douban Moment.
Stars: ✭ 1,147 (+1174.44%)
Mutual labels:  coroutines, kotlin-coroutines
Corbind
Kotlin Coroutines binding APIs for Android UI widgets from the platform and support libraries
Stars: ✭ 357 (+296.67%)
Mutual labels:  coroutines, kotlin-coroutines
Kroto Plus
gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc
Stars: ✭ 400 (+344.44%)
Mutual labels:  coroutines, kotlin-coroutines
Modular App Core
Core implementations for a modular Android App
Stars: ✭ 127 (+41.11%)
Mutual labels:  coroutines, kotlin-coroutines
ridge
Pure asynchronous PHP implementation of the AMQP 0-9-1 protocol.
Stars: ✭ 49 (-45.56%)
Mutual labels:  amqp, rabbitmq-client

The White Rabbit

Build Status Download Open Source Helpers codecov License: MIT Gitter

The White Rabbit is a fast and asynchronous RabbitMQ (AMQP) client library based on Kotlin coroutines. Currently the following features are supported:

  • Queue and exchange manipulations
  • Message publishing with confirmation
  • Message consuming with acknowledgment
  • Transactional publishing and consuming
  • RPC pattern

Adding to project

Gradle
repositories {
    jcenter()
}

compile 'com.viartemev:the-white-rabbit:$version'
Maven
<repositories>
    <repository>
        <id>jcenter</id>
        <url>https://jcenter.bintray.com/</url>
    </repository>
</repositories>

<dependency>
  <groupId>com.viartemev</groupId>
  <artifactId>the-white-rabbit</artifactId>
  <version>${version}</version>
</dependency>

Usage notes and examples

Use one of the extension methods on com.rabbitmq.client.Connection to get a channel you need:

connection.channel { 
    /*
    The plain channel with consumer acknowledgments, supports:
        -- queue and exchange manipulations
        -- asynchronous consuming
        -- RPC pattern
     */
}

connection.confirmChannel { // 
    /*
    Channel with publisher confirmations, additionally supports:
        -- asynchronous message publishing
     */
}

connection.txChannel { // transactional support
    /*
    Supports transactional publishing and consuming.
     */
}

Queue and exchange manipulations

Asynchronous exchange declaration

connection.channel.declareExchange(ExchangeSpecification(EXCHANGE_NAME))

Asynchronous queue declaration

connection.channel.declareQueue(QueueSpecification(QUEUE_NAME))

Asynchronous queue binding to an exchange

connection.channel.bindQueue(BindQueueSpecification(EXCHANGE_NAME, QUEUE_NAME))

Asynchronous message publishing with confirmation

connection.confirmChannel {
    publish {
        val messages = (1..n).map { createMessage("Hello #$it") }
        publishWithConfirmAsync(coroutineContext, messages).awaitAll()
    }
}

or

connection.confirmChannel {
     publish {
        coroutineScope {
            val messages = (1..n).map { createMessage("Hello #$it") }
            messages.map { async { publishWithConfirm(it) } }
        }
    }
}

Asynchronous message consuming with acknowledgement

Consume only n-messages:

connection.channel {
    consume(QUEUE_NAME, PREFETCH_COUNT) {
        (1..n).map { async { consumeMessageWithConfirm({ println(it) }) } }.awaitAll()
    }
}

Transactional publishing and consuming

RabbitMQ and AMQP itself offer rather scarce support for transaction. When considering using transactions you should be aware that:

  • a transaction could only span one channel and one queue;
  • com.rabbitmq.client.Channel is not thread-safe;
  • channel can be either in confirm mode or in transaction mode at a time;
  • transactions cannot be nested into each other;

The library provides a convenient way to perform transactional publishing and receiving based on transaction extension function. This function commits a transaction upon normal execution of the block and rolls it back if a RuntimeException occurs. Exceptions are always propagated further. Coroutines are not used for publishing though, since there are no any asynchronous operations involved.

connection.txChannel {
    transaction {
        val message = createMessage(queue = oneTimeQueue, body = "Hello from tx")
        publish(message)
    }
}

RPC pattern

connection.channel {
    val message = RabbitMqMessage(MessageProperties.PERSISTENT_BASIC, "Hello world".toByteArray())
    coroutineScope {
        (1..10).map {
            async {
                rpc {
                    call(requestQueueName = "rpc_request", message = message)
                        .also { println("Reply: ${String(it.body)}") }
                }
            }
        }.awaitAll()
    }
}

Links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].