Extensive Redis Pub-Sub wrapper for lettuce written in Kotlin

Overview

aware

Extensive annotation-based Redis Pub-Sub wrapper for lettuce written in Kotlin.

  • Aware was written to be a replacement for the very dated Banana library.
  • Aware allows for both asynchronous and synchronous contexts.
  • Aware contain wrappers for the RedisCodec .
    • These codec wrappers are only used for message values, therefore they only accept one type, V. (WrappedRedisCodec )
    • We have multiple wrapper types available:
      • StringRedisCodec
      • JsonRedisCodec
        • AwareMessageCodec (A default implementation of JsonRedisCodec, for the AwareMessage)
  • Aware uses a platform-level credential & serialization provider.
    • Aware currently ONLY supports Gson.
    • Aware credential & serialization providers can be configured by using AwareHub#configure()
  • Aware is an annotation-based.
    • More traditional solutions will be implemented in the future.

Conversations:

Aware has a conversation feature where A can contact B and await for a reply (which could possibly be empty).

Conversation models:

Conversations require you to create your own implementation of ConversationMessage & ConversationMessageResponse.

  • These models can contain anything which is serializable by the Gson instance provided in your AwareHub configuration.
  • The response model must contain the uniqueId of the origin message to allow it to be processed back on the original application.

Channel naming:

Conversation factories require a channel suffix, which will then used for both outgoing and incoming channels.

  • Outgoing:
    • og-${suffix}
  • Incoming:
    • ic-${suffix}

How to create a new ConversationFactory:

println("Original msg: ${message.message}") println("Response: ${response.message}") return@receive ConversationContinuation.END } .build()">
val conversationFactory = ConversationFactoryBuilder
    .of<ConversationMessageImpl, ConversationResponseImpl>()
    // your channel suffix
    .channel("big-monkey")
    // your timeout, this is not optional.
    .timeout(2L, TimeUnit.SECONDS) {
        println("Lmao no response dam")
    }
    // what will be handled on the response of a message
    // the origin ConversationMessage is supplied as a lambda parameter
    .response {
        ConversationResponseImpl(
            "on god", it.uniqueId
        )
    }
    // what will be handled when our backend receives a response to a message
    .receive { message, response ->
        println("Original msg: ${message.message}")
        println("Response: ${response.message}")

        return@receive ConversationContinuation.END
    }
    .build()

Usage:

An example annotation-based pub-sub subscription for an AwareMessage codec:

("horse") println("Hey! This is the \"horse\". ($horse)") }">
@Subscribe("test")
@ExpiresIn(30L, TimeUnit.SECONDS)
fun onTestExpiresIn30Seconds(
    message: AwareMessage
)
{
    val horse = message.retrieve<String>("horse")

    println("Hey! This is the \"horse\". ($horse)")
}

And a lambda-based one:

("horse") println("Hey! This is the \"horse\". $horse") }">
aware.listen(
    "test",
    ExpiresIn(30L, TimeUnit.SECONDS)
) {
    val horse = retrieve<String>("horse")

    println("Hey! This is the \"horse\". $horse")
}

An example AwareMessage use case:

AwareMessage.of(
    "test", aware,
    "horse" to "heyy-${Random.nextFloat()}"
).publish(
    // supplying our own thread context
    AwareThreadContext.SYNC
)

An example AwareHub configuration:

AwareHub.configure(
    // the default credentials would be localhost:6379, no password.
    WrappedAwareUri() 
) {
    gson
}

An example AwareBuilder configuration:

val aware = AwareBuilder
    .of<AwareMessage>("twitter.com/growlygg")
    // You can do this:
    .codec(AwareMessageCodec)
    // Or you can do this:
    .codec(JsonRedisCodec.of { it.packet })
    .build()

Future plans:

  • None yet! Message me on Discord (growly#4953) if you have any suggestions!

Other information:

lettuce-core is automatically shaded into the final shadowJar. kotlin-stdlib & kotlin-reflect are NOT.

  • Although aware has not been tested in a production environment, it has run perfectly fine under multiple tests.
    • All of aware's features have now been testing.

Note:

If you're using this in a closed-source project, please add GrowlyX to the project's author section.

You might also like...
Xoxo is a simple wrapper around org.w3c.dom to parse XML using nice Kotlin APIs

Xoxo 😘 Xoxo is a simple wrapper around org.w3c.dom to parse XML using nice Kotlin APIs. No more NodeList, .item(), etc... just use .children, .filter

Simple api wrapper for nekos.life

nekos-kt Simple api wrapper for nekos.life Installation Maven: repositories repository idjitpack.io/id urlhttps://jitpack.io/url

KataContacts written in Kotlin. The main goal is to practice Clean Architecture Development

KataContacts written in Kotlin We are here to practice Clean Architecture Development. Clean Architecture is a way of structuring code. We are going t

A simple android Twitter client written in Kotlin
A simple android Twitter client written in Kotlin

Blum Blum is an unofficial, simple, fast Twitter client written in Kotlin. This project is a complete rewrite of the Java version. Screenshot Build To

📚  Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.
📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Android Components Architecture in a Modular Word Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 app

A showcase music app for Android entirely written using Kotlin language

Bandhook Kotlin This project is a small replica of the app I developed some time ago. Bandhook can still be found on Play Store At the moment it will

Mobile client for official Nextcloud News App written as Kotlin Multiplatform Project
Mobile client for official Nextcloud News App written as Kotlin Multiplatform Project

Newsout Android and iOS mobile client for Nextcloud news App. The Android client is already available to download in the Play Store. F-Droid and Apple

an open source algorithmic trading framework written in Kotlin for anyone serious about algo-trading
an open source algorithmic trading framework written in Kotlin for anyone serious about algo-trading

Roboquant Roboquant is an algorithmic trading platform that is fast and flexible while at the same time strives to be easy to use. It is fully open so

These files are included in an Android Studio Project for a Magic the Gathering Life Counter app. The app was written in Kotlin.
These files are included in an Android Studio Project for a Magic the Gathering Life Counter app. The app was written in Kotlin.

Magic-Life-Counter These files were created in Android Studio using Kotlin. Usage This app was made to keep track of life totals while playing the tra

Owner
Subham
@scalagg, @lmaodesign.
Subham
Kreds - a thread-safe, idiomatic, coroutine based Redis client written in 100% Kotlin

Kreds Kreds is a thread-safe, idiomatic, coroutine based Redis client written in 100% Kotlin. Why Kreds? Kreds is designed to be EASY to use. Kreds ha

Abhijith Shivaswamy 117 Dec 23, 2022
🎲 Kotlin Symbol Processor to auto-generate extensive sealed classes and interfaces for Android and Kotlin.

SealedX ?? Kotlin Symbol Processor to auto-generate extensive sealed classes and interfaces for Android and Kotlin. Why SealedX? SealedX generates ext

Jaewoong Eum 236 Nov 30, 2022
An extensive collection of Kotlin Android Utils

An extensive collection of Kotlin Android Utils This library contains small helper functions used throughout almost all of my other projects. The goal

Allan Wang 207 Dec 23, 2022
A simple, lightweight, non-bloated redis client for kotlin and other JVM languages

rekt is a lightweight, non-bloated redis client, primarily written for the kotlin programming language, while also supporting other JVM-based languages, such as Java, Scala, and obviously way more.

Patrick 8 Nov 2, 2022
A spring-boot project that demonstrates data caching using Redis

A spring-boot project that demonstrates data caching using Redis

Sakawa Bob 1 Mar 26, 2022
Reia is the Redis Pubsub client that Manase uses to communicate with other modules or nodes.

from Mana Reia is a simple wrapper around Lettuce to enable easy usage of its Redis Pubsub client. This library is only intended to be used for sendin

Mana 1 Apr 29, 2022
MMKV for Kotlin Multiplatform is a wrapper for MMKV using Kotlin API

MMKV for Kotlin Multiplatform is a wrapper for MMKV using Kotlin API

Ctrip, Inc. 65 Dec 29, 2022
Katbox - Kotlin wrapper for catbox.moe and litterbox.catbox.moe

katbox katbox is a Kotlin multiplatform wrapper written with ktor and coroutines

Oliver Berg 2 Oct 5, 2022
Katoot - An easy-to-use (blocking) Kotlin wrapper for Kahoot's REST api

katoot An easy-to-use (blocking) Kotlin wrapper for Kahoot's REST api. Usage Qui

Subham 1 Jul 17, 2022
Asynchronous Spring Initializr API wrapper for Kotlin/JVM

initializr-kt Asynchronous Spring Initializr API wrapper for Kotlin/JVM. This library provides the simplest DSL for initializing Spring Boot projects

Mikhail Titov 2 May 8, 2022