cb372 / finagle-beanstalk   0.1.0

GitHub

A Scala client for beanstalkd, based on Finagle RPC framework.

Scala versions: 2.11

finagle-beanstalk

Build Status Maven Central

An asynchronous Scala client for beanstalkd built with Finagle.

Versioning

Built for Scala 2.11.x.

How to use

Add the following dependency to your sbt build file:

libraryDependencies += "com.github.cb372" %% "finagle-beanstalk" % "0.0.1"

In your Scala application, create a new BeanstalkClient by passing it a comma-separated list of host:port pairs:

import com.github.cb372.finagle.beanstalk.client.BeanstalkClient

val client = BeanstalkClient.build("host1:11300,host2:11300")

Then use it, e.g.:

val jobData = "foo"
val putOptions = PutOpts(priority = 1, delay = 2, timeToRun = 3)
val futureOfResponse: Future[Either[Reply, Int]] = client.put(jobData, putOptions)
futureOfResponse map {
  case Left(reply) => 
    // Server replied with an error.
    // Pattern match on it to find out what it was.
  case Right(id) =>
    // The job was successfully inserted.
    // This is the job ID.
}

Finally shut down the client:

client.quit()

How to run the tests

Make sure you have beanstalkd installed and available on your $PATH. The tests will automatically start a beanstalkd server on a random port.

Then run:

$ sbt test