GithubHelp home page GithubHelp logo

virusbear / beanstalkt Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 98 KB

Async kotlin client for beanstalkd work queue

License: Apache License 2.0

Kotlin 99.67% Java 0.33%
beanstalkd-client kotlin-coroutines kotlin-library

beanstalkt's Introduction

beanstalkt

Build Status Kotlin GitHub Maven Central

A simple async kotlin client for beanstalkd work queue.

Description

This client implements all operations of beanstalkd as described in the protocol documentation.

All operations are implemented to be suspending functions, suspending the caller until a response is received by beanstalkd.

Usage

suspend fun main() = coroutineScope {
    val client = DefaultClient()

    while(true) {
        val job = client.reserve()
        println(job.id)
    }
}

Known Issues

Due to the blocking nature of the beanstalk protocol, it is currently not possible to have a client reserve a job, whilst performing other operations asynchronously. All operations are added to an internal queue and processed sequentially. To avoid blocking issues with the reserve operation, use the reserveWithTimeout() operation to execute other operations after a suitable timeout.

suspend fun main() = coroutineScope {
    val client = DefaultClient()

    val producerJob = launch {
        while(true) {
            client.put("Hello World!".toByteArray())
        }
    }
    
    val consumerJob = launch {
        while(true) {
            try {
                val job = client.reserveWithTimeout(10.0.seconds)
                println(job.id)
            } catch(ex: TimedOutException) {
                //Ignored
            }
        }
    }
    
    producerJob.join()
    consumerJob.join()
}

Features

  • beanstalkd protocol completely implemented
  • Connection Pooling
  • suspending iterator similar to kotlin Channel implementation
  • Kotlin Multiplatform

Using in your projects

Maven

Add dependencies (you can also add other modules that you need):

<dependency>
    <groupId>com.virusbear.beanstalkt</groupId>
    <artifactId>beanstalkt</artifactId>
    <version>1.0.0</version>
</dependency>

And make sure that you use the latest Kotlin version:

<properties>
    <kotlin.version>1.9.0</kotlin.version>
</properties>

Gradle

Add dependencies (you can also add other modules that you need):

dependencies {
    implementation("com.virusbear.beanstalkt:beanstalkt:1.0.0")
}

And make sure that you use the latest Kotlin version:

plugins {
    // For build.gradle.kts (Kotlin DSL)
    kotlin("jvm") version "1.9.0"
    
    // For build.gradle (Groovy DSL)
    id "org.jetbrains.kotlin.jvm" version "1.9.0"
}

Make sure that you have mavenCentral() in the list of repositories:

repositories {
    mavenCentral()
}

State of Dev & Contributing

This project is only a side project of mine, which originated from another project. I will try to fix any bugs I encounter during my own use cases, but will most likely be unable to work on parts that I am not personally using.

If you encounter any bugs or have ideas on how to improve this project, please file an issue or create a pull request.

Any help is appreciated.

Building

To build this project run the gradle build task.

CLI

./gradlew build

beanstalkt's People

Contributors

virusbear avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.