Code: Queues and messaging: Resque, AMQP, MQTT and ZeroMQ
Queues and messaging: the code
The programs behind the slides, grouped by module. They use only bundled modules (resque, redis, amqp, mqtt, zmq), need no decks, and run with Jennifer 0.27.0. Run every command from this folder. All passwords are placeholders (demo / changeme, ada / s3cret).
Servers
Each server runs in a local container bound to 127.0.0.1. Remove them afterwards with docker rm -f <name>.
- Redis 7 for Resque:
docker run -d --name academy-talk-qredis -p 127.0.0.1:16380:6379 redis:7 - RabbitMQ 4:
docker run -d --name academy-talk-rabbitmq -p 127.0.0.1:25672:5672 -e RABBITMQ_DEFAULT_USER=demo -e RABBITMQ_DEFAULT_PASS=changeme rabbitmq:4(it needs about 10 s to start) - Mosquitto 2 with a password: first
sh mqtt/mosquitto/make-passwd.sh, which writesmqtt/mosquitto/passwdfordemo/changeme, thendocker run -d --name academy-talk-mosquitto -p 127.0.0.1:11883:1883 -v "$PWD/mqtt/mosquitto/mosquitto.conf":/mosquitto/config/mosquitto.conf:ro -v "$PWD/mqtt/mosquitto/passwd":/mosquitto/config/passwd:ro eclipse-mosquitto:2 - Ruby with the resque gem (3.2.0 in the talk), on the host network so it reaches Redis at 127.0.0.1:16380:
docker run -d --name academy-talk-ruby --network host -v "$PWD/resque":/app ruby:3.3 sleep 3600anddocker exec academy-talk-ruby gem install resque --no-document - Python with pyzmq (27.3 with libzmq 4.3.5 in the talk), also on the host network:
docker run -d --name academy-zmq-py --network host -v "$PWD/zmq":/w python:3.13-slim sleep 3600anddocker exec academy-zmq-py pip install -q pyzmq
The ZeroMQ programs other than slowjoin.j and plain.j need no server at all: both ends run inside one Jennifer program.
Resque on Redis
resque/produce.j: enqueues four jobs on two queues and shows the stored JSON ("Resque: enqueue a job"). Run:jennifer run resque/produce.jresque/worker.j: a worker loop withreserveBlocking, retries and the failed list ("A worker is your own loop", "Failures and retries are yours"). Run afterproduce.j:jennifer run resque/worker.jresque/interop.rbandresque/interop.j: Ruby and Jennifer on the same queue ("Same queue, Ruby on the other side"). Run:docker exec academy-talk-ruby ruby /app/interop.rb enqueue, thenjennifer run resque/interop.j, thendocker exec academy-talk-ruby ruby /app/interop.rb workresque/pool.j: a producer and four spawned workers, each with its own connection ("A pool of workers with spawn"). Run:jennifer run resque/pool.j
AMQP on RabbitMQ
amqp/publish.j: declares theorderstopic exchange and thebillingqueue, binds them and publishes with confirms ("AMQP: exchange, queue, binding", "Confirms: one wait per publish"). Run:jennifer run amqp/publish.jamqp/bad.j: publishes one order that is not valid JSON, for the nack path ofpull.j. Run:jennifer run amqp/bad.jamqp/pull.j:get, thenackornack("Pull: get, then ack or nack"). Run:jennifer run amqp/pull.jamqp/one.j: publishes one more order. Run:jennifer run amqp/one.jamqp/consume.j: a consumer in its own spawn with its own connection ("Push: a consumer in its own spawn"). Run:jennifer run amqp/consume.jamqp/crash.j: takes a message and exits without an ack, so it is redelivered ("What happens to an unacked message"). Run:jennifer run amqp/one.j,jennifer run amqp/crash.j,docker exec academy-talk-rabbitmq rabbitmqctl list_queues name messages_ready messages_unacknowledged, thenjennifer run amqp/consume.j(it waits for three messages, so publish more withone.jif needed)
MQTT on Mosquitto
mqtt/wildcards.j:+and#subscriptions, QoS 0 and QoS 1 publishes ("MQTT: topics and wildcards", "QoS 0 and QoS 1"). Run:jennifer run mqtt/wildcards.jmqtt/sameclient_qos1.jandmqtt/sameclient_subscribe.j: one client that publishes and subscribes, the 0.26.0 limitation in the last bullet of "QoS 0 and QoS 1". Run:jennifer run mqtt/sameclient_qos1.j,jennifer run mqtt/sameclient_subscribe.jmqtt/will.j: a retained status and a last will on a cut connection ("Retained messages and the last will"). Run:jennifer run mqtt/will.jmqtt/reconnect.j: a subscriber that reconnects with a growing pause ("Reconnect with a backoff"). Run:jennifer run mqtt/reconnect.j, thendocker restart academy-talk-mosquittoandjennifer run mqtt/publish.jtwice;mqtt/publish.jsends onehome/hall/lightmessage
ZeroMQ
zmq/reqrep.j: REQ and REP in one program ("ZeroMQ: no broker, just sockets"). Run:jennifer run zmq/reqrep.jzmq/pushpull.j: a ventilator and four workers ("PUSH / PULL: a ventilator and its workers"). Run:jennifer run zmq/pushpull.jzmq/pubsub.j: prefix subscriptions ("PUB / SUB: prefixes, filtered by the subscriber"). Run:jennifer run zmq/pubsub.jzmq/polltrap.j: an emptypollon a SUB after a dropped message (the notes of "PUB / SUB"). Run:jennifer run zmq/polltrap.jzmq/ticker.pyandzmq/slowjoin.j: the slow joiner against a pyzmq PUB ("Talking to libzmq, with PLAIN"). Run:docker exec -d academy-zmq-py python /w/ticker.py; jennifer run zmq/slowjoin.jzmq/plainrep.pyandzmq/plain.j: PLAIN authentication against a pyzmq REP with a ZAP handler ("Talking to libzmq, with PLAIN"). Run:docker exec -d academy-zmq-py python /w/plainrep.py; sleep 1; jennifer run zmq/plain.jzmq/hwm.j: a reader that never reads;sendblocks once the TCP buffers are full, there is no high-water mark (notes of "Delivery guarantees compared"). Run:jennifer run zmq/hwm.j(the sender stalls after about 30 to 40 messages; the "unwaited spawn error" at the end comes from the cancelled sender when the reader is closed, and is expected)zmq/errors.j: the ZeroMQ rows of the error table, withZmqErrorandpeerReason("Errors you will actually see"). Run:jennifer run zmq/errors.j
Errors
errors.j: the AMQP, MQTT and Redis rows of the error table: no broker, a wrong password, a missing queue ("Errors you will actually see"). Needs RabbitMQ and Mosquitto running (ports 25999, 11999 and 16999 stay unused on purpose). Run:jennifer run errors.j
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 6.1 KiB | raw |
| amqp/bad.j | 218 B | raw |
| amqp/consume.j | 734 B | raw |
| amqp/crash.j | 389 B | raw |
| amqp/one.j | 218 B | raw |
| amqp/publish.j | 974 B | raw |
| amqp/pull.j | 670 B | raw |
| errors.j | 1.2 KiB | raw |
| mqtt/mosquitto/make-passwd.sh | 331 B | raw |
| mqtt/mosquitto/mosquitto.conf | 75 B | raw |
| mqtt/publish.j | 319 B | raw |
| mqtt/reconnect.j | 1.1 KiB | raw |
| mqtt/sameclient_qos1.j | 562 B | raw |
| mqtt/sameclient_subscribe.j | 455 B | raw |
| mqtt/wildcards.j | 1021 B | raw |
| mqtt/will.j | 1.0 KiB | raw |
| resque/interop.j | 520 B | raw |
| resque/interop.rb | 413 B | raw |
| resque/pool.j | 1.0 KiB | raw |
| resque/produce.j | 723 B | raw |
| resque/worker.j | 1.3 KiB | raw |
| zmq/errors.j | 1.9 KiB | raw |
| zmq/hwm.j | 793 B | raw |
| zmq/plain.j | 675 B | raw |
| zmq/plainrep.py | 363 B | raw |
| zmq/polltrap.j | 642 B | raw |
| zmq/pubsub.j | 867 B | raw |
| zmq/pushpull.j | 923 B | raw |
| zmq/reqrep.j | 595 B | raw |
| zmq/slowjoin.j | 348 B | raw |
| zmq/ticker.py | 223 B | raw |