An asynchronous Scala client for beanstalkd built with Finagle.
Built for Scala 2.11.x.
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()
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