Py-queue-db 是一个开源项目,旨在提供一个类似 Kafka 的消息队列数据库的 Python 实现。该项目使用 SQLite 作为后端存储,并提供了一个简单的 HTTP API 来发布、轮询和提交消息。
- 消息发布:通过 HTTP POST 请求发布消息到指定主题。
- 消息轮询:通过 HTTP GET 请求从指定主题轮询消息。
- 消息提交:通过 HTTP POST 请求提交消费者组的偏移量。
-
克隆项目仓库:
git clone https://github.com/CodeBub/py-queue-db.git cd py-queue-db
-
安装依赖:
pip install aiohttp
-
启动服务器:
python py-queue-db.py
-
发布消息:
curl -X POST -H "Content-Type: application/json" -d '{"topic": "test_topic", "message": {"key": "value"}}' http://localhost:8080/publish
-
轮询消息:
curl "http://localhost:8080/poll?topic=test_topic&consumer_group=test_group&timeout=5"
-
提交偏移量:
curl -X POST -H "Content-Type: application/json" -d '{"topic": "test_topic", "consumer_group": "test_group", "offset": 10}' http://localhost:8080/commit
- URL:
/publish
- Method:
POST
- Request Body:
{ "topic": "string", "message": "object" }
- Response:
{ "status": "ok", "message_id": "integer" }
- URL:
/poll
- Method:
GET
- Query Parameters:
topic
: 主题名称consumer_group
: 消费者组名称timeout
: 超时时间(秒),默认值为 0
- Response:
{ "messages": [ { "id": "integer", "message": "object" } ] }
- URL:
/commit
- Method:
POST
- Request Body:
{ "topic": "string", "consumer_group": "string", "offset": "integer" }
- Response:
{ "status": "ok" }
欢迎贡献代码、报告问题或提出建议。请查看 CONTRIBUTING.md 了解更多信息。
本项目采用 MIT 许可证。