返回 2026-04-24
⚙️ 工程

russellromney/honker:为 SQLite 实现 Postgres NOTIFY/LISTEN 语义russellromney/honker

simonwillison.net·2026-04-24 节选正文

该项目将 PostgreSQL 的 NOTIFY/LISTEN 通知机制移植到 SQLite,通过 Rust 编写的 SQLite 扩展和多种语言绑定(包括 Python)实现。它允许开发者在 SQLite 中使用类似消息队列的异步通信模式,显著提升轻量级应用的事件驱动能力。设计简洁高效,适用于需要低延迟通知的场景。

Simon Willison

24th April 2026 - Link Blog

russellromney/honker (via) "Postgres NOTIFY/LISTEN semantics" for SQLite, implemented as a Rust SQLite extension and various language bindings to help make use of it.

The design of this looks very solid. It lets you write Python code for queues that looks like this:

import honker

db = honker.open("app.db")
emails = db.queue("emails")
emails.enqueue({"to": "alice@example.com"})

# Consume (in a worker process)
async for job in emails.claim("worker-1"):
    send(job.payload)
    job.ack()

And Kafka-style durable streams like this:

stream = db.stream("user-events")

with db.transaction() as tx:
    tx.execute("UPDATE users SET name=? WHERE id=?", [name, uid])
    stream.publish({"user_id": uid, "change": "name"}, tx=tx)

async for event in stream.subscribe(consumer="dashboard"):
    await push_to_browser(event)

It also adds 20+ custom SQL functions including these two:

SELECT notify('orders', '{"id":42}');
SELECT honker_stream_read_since('orders', 0, 1000);

The extension requires WAL mode, and workers can poll the .db-wal file with a stat call every 1ms to get as close to real-time as possible without the expense of running a full SQL query.

honker implements the transactional outbox pattern, which ensures items are only queued if a transaction successfully commits. My favorite explanation of that pattern remains Transactionally Staged Job Drains in Postgres by Brandur Leach. It's great to see a new implementation of that pattern for SQLite.

需要完整排版与评论请前往来源站点阅读。