{"id":28943078,"url":"https://github.com/flixcoder/bonsaimq","last_synced_at":"2025-10-10T07:16:40.076Z","repository":{"id":38007614,"uuid":"496547215","full_name":"FlixCoder/bonsaimq","owner":"FlixCoder","description":"Message/job queue based on bonsaidb, similar to sqlxmq.","archived":true,"fork":false,"pushed_at":"2025-04-06T14:59:28.000Z","size":75,"stargazers_count":7,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-04T02:57:19.661Z","etag":null,"topics":["database","message","persistent","queue","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/bonsaimq","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FlixCoder.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["FlixCoder"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-05-26T08:52:30.000Z","updated_at":"2025-09-13T22:16:50.000Z","dependencies_parsed_at":"2023-12-21T22:25:01.490Z","dependency_job_id":"2daa8a07-45d0-49f3-acab-4e1be57fb767","html_url":"https://github.com/FlixCoder/bonsaimq","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":"0.33333333333333337","last_synced_commit":"5115980b6716f59be00edfefa58f546a590a5224"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/FlixCoder/bonsaimq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlixCoder%2Fbonsaimq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlixCoder%2Fbonsaimq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlixCoder%2Fbonsaimq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlixCoder%2Fbonsaimq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FlixCoder","download_url":"https://codeload.github.com/FlixCoder/bonsaimq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlixCoder%2Fbonsaimq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003169,"owners_count":26083533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","message","persistent","queue","rust"],"created_at":"2025-06-23T04:41:03.841Z","updated_at":"2025-10-10T07:16:40.071Z","avatar_url":"https://github.com/FlixCoder.png","language":"Rust","funding_links":["https://github.com/sponsors/FlixCoder"],"categories":[],"sub_categories":[],"readme":"# Bonsaimq\n\n[![crates.io page](https://img.shields.io/crates/v/bonsaimq.svg)](https://crates.io/crates/bonsaimq)\n[![docs.rs page](https://docs.rs/bonsaimq/badge.svg)](https://docs.rs/bonsaimq/)\n![license: MIT](https://img.shields.io/crates/l/bonsaimq.svg)\n\nSimple database message queue based on [bonsaidb](https://github.com/khonsulabs/bonsaidb).\n\nThe project is highly influenced by [sqlxmq](https://github.com/Diggsey/sqlxmq).\n\nWarning: This project is in early alpha and should not be used in production!\n\n## Usage\n\nImport the project using:\n\n```bash\ncargo add bonsaimq\n```\n\nor\n\n```toml\n# adjust the version to the latest version:\nbonsaimq = \"0.3.0\"\n# or\nbonsaimq = { git = \"https://github.com/FlixCoder/bonsaimq\" }\n```\n\nThen you can use the message/job queue as follows:\n\n- You need job handlers, which are async functions that receive one argument of type `CurrentJob` and return nothing. `CurrentJob` allows interfacing the job to retrieve job input or complete the job etc.\n- The macro `job_regristy!` needs to be use to create a job registry, which maps message names/types to the job handlers and allows spawning new jobs.\n- A job runner needs to be created and run on a bonsai database. It runs in the background as long as the handle is in scope and executes the jobs according to the incoming messages. It acts on the job registry.\n\n## Example\n\nBesides the following simple example, see the examples in the [examples folder](https://github.com/FlixCoder/bonsaimq/tree/main/examples/) and take a look at the tests.\n\n```rust\nuse bonsaidb::local::{\n    config::{Builder, StorageConfiguration},\n    AsyncDatabase,\n};\nuse bonsaimq::{job_registry, CurrentJob, JobRegister, JobRunner, MessageQueueSchema};\nuse color_eyre::Result;\n\n/// Example job function. It receives a handle to the current job, which gives\n/// the ability to get the input payload, complete the job and more.\nasync fn greet(mut job: CurrentJob) -\u003e color_eyre::Result\u003c()\u003e {\n    // Load the JSON payload and make sure it is there.\n    let name: String = job.payload_json().expect(\"input should be given\")?;\n    println!(\"Hello {name}!\");\n    job.complete().await?;\n    Ok(())\n}\n\n// The JobRegistry provides a way to spawn new jobs and provides the interface\n// for the JobRunner to find the functions to execute for the jobs.\njob_registry!(JobRegistry, {\n    Greetings: \"greet\" =\u003e greet,\n});\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c()\u003e {\n    // Open a local database for this example.\n    let db_path = \"simple-doc-example.bonsaidb\";\n    let db = AsyncDatabase::open::\u003cMessageQueueSchema\u003e(StorageConfiguration::new(db_path)).await?;\n\n    // Start the job runner to execute jobs from the messages in the queue in the\n    // database.\n    let job_runner = JobRunner::new(db.clone()).run::\u003cJobRegistry\u003e();\n\n    // Spawn new jobs via a message on the database queue.\n    let job_id = JobRegistry::Greetings.builder().payload_json(\"cats\")?.spawn(\u0026db).await?;\n\n    // Wait for job to finish execution, polling every 100 ms.\n    bonsaimq::await_job(job_id, 100, \u0026db).await?;\n\n    // Clean up.\n    job_runner.abort(); // Is done automatically on drop.\n    tokio::fs::remove_dir_all(db_path).await?;\n    Ok(())\n}\n```\n\n## Minimum supported Rust version\n\nCurrently, I am always using the latest Rust version and do not put in any effort to keep the MSRV. Please open an issue in case you need a different policy, I might consider changing the policy.\n\n## License\n\nLicensed under the MIT license. All contributors agree to license under this license.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflixcoder%2Fbonsaimq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflixcoder%2Fbonsaimq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflixcoder%2Fbonsaimq/lists"}