Beanstalk and Python in FreeBSD
December 22 2016160 words, ~1 min. read
beanstalk, freebsd, python, worker, queue
Beanstalk is a simple, fast work queue, inspired by the simplicity of memcached. Like memcached, it has rich client support in multiple languages. Being a text protocol, writing a new client is easy (if not already available).
Server
Install
pkg install beanstalkd
Run daemon
The daemon could be run using any of the following,
beanstalkdbeanstalkd -l 127.0.0.1beanstalkd -l 192.168.1.11 -p 11301beanstalkd -b <log dir>
The -l and -p arguments are used to specify listen address (default 0.0.0.0) and port (default 11300) accordingly. The -b argument accepts a directory location for binary logging and is useful to make the queues persistent across restarts.
Client
Install
$ sudo pkg install py27-virtualenv
$ virtualenv worker
$ . worker/bin/activate
(worker) $ pip install yolk beanstalkc pyyaml
producer.py
#!/usr/bin/env python
import beanstalkc
b = beanstalkc.Connection(host='192.168.1.11')
b.put('Hello')
consumer.py
#!/usr/bin/env python
import beanstalkc
b = beanstalkc.Connection(host='192.168.1.11')
job = b.reserve()
print( job.body )
job.delete()
TIPS
- Use beanwalker to monitor
- Refer beanstalkc tutorial for more information