{"id":22908918,"url":"https://github.com/nrempel/unisub","last_synced_at":"2025-05-08T23:09:34.701Z","repository":{"id":197886016,"uuid":"699656022","full_name":"nrempel/unisub","owner":"nrempel","description":"A Pub/Sub library for Rust backed by Postgres","archived":false,"fork":false,"pushed_at":"2023-10-03T05:01:07.000Z","size":13,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-08T23:09:29.191Z","etag":null,"topics":["postgres","pubsub","rust"],"latest_commit_sha":null,"homepage":"","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/nrempel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-03T04:26:01.000Z","updated_at":"2024-07-08T16:45:17.000Z","dependencies_parsed_at":"2023-10-03T08:08:56.991Z","dependency_job_id":null,"html_url":"https://github.com/nrempel/unisub","commit_stats":null,"previous_names":["nrempel/unisub"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrempel%2Funisub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrempel%2Funisub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrempel%2Funisub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrempel%2Funisub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nrempel","download_url":"https://codeload.github.com/nrempel/unisub/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253160776,"owners_count":21863629,"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","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":["postgres","pubsub","rust"],"created_at":"2024-12-14T03:33:14.247Z","updated_at":"2025-05-08T23:09:34.668Z","avatar_url":"https://github.com/nrempel.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unisub\n\n[![Crates.io](https://img.shields.io/crates/v/unisub.svg)](https://crates.io/crates/unisub) [![Docs.rs](https://docs.rs/unisub/badge.svg)](https://docs.rs/unisub)\n\nUnisub is a Pub/Sub library for Rust, using Postgres as the backend. It offers a convenient way to publish and subscribe to messages across different topics.\n\n## Features\n\n- Publish messages to topics\n- Subscribe to topics to receive messages\n- Create and remove topics\n- Includes a convenience binary for managing topics and running migrations\n- Asynchronous design using Tokio\n\n## Installation\n\nAdd Unisub as a dependency in your `Cargo.toml`:\n\n```toml\n[dependencies]\nunisub = \"*\"\n```\n\n## Setting up the Postgres Environment\n\n1. Install Postgres if you haven't already. You can download it from [here](https://www.postgresql.org/download/).\n2. Create a new database and note the connection URL.\n3. Make sure your Postgres database is accessible and running.\n\n### Environment Variable\n\nSet an environment variable called `DATABASE_URL` with the Postgres connection URL.\n\n```bash\nexport DATABASE_URL=postgres://username:password@localhost/dbname\n```\n\n### Running Migrations and Setting Up Topics\n\n#### Using CLI\n\nFirst, run the migrations:\n\n```bash\nunisub migrate\n```\n\nThen you can add your topics:\n\n```bash\nunisub add-topic my_topic\n```\n\n#### Programmatically\n\n```rust\nuse unisub::PubSub;\nuse unisub::migrate;\nuse sqlx::PgPool;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), unisub::Error\u003e {\n    let pool = PgPool::connect(\"your_database_url\").await?;\n    migrate(\u0026pool).await?;\n    let mut pubsub = PubSub::new(pool).await?;\n    pubsub.add_topic(\"my_topic\").await?;\n    Ok(())\n}\n```\n\n## Usage\n\n### Library\n\n```rust\nuse unisub::PubSub;\nuse sqlx::PgPool;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), unisub::Error\u003e {\n    let pool = PgPool::connect(\"your_database_url\").await?;\n    let mut pubsub = PubSub::new(pool).await?;\n    pubsub.push(\"my_topic\", b\"My message\").await?;\n    Ok(())\n}\n```\n\nAnd here's an example of how to subscribe to a topic:\n\n```rust\nuse unisub::PubSub;\nuse sqlx::PgPool;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), unisub::Error\u003e {\n    // Connect to the database\n    let pool = PgPool::connect(\"your_database_url\").await?;\n    let mut pubsub = PubSub::new(pool).await?;\n\n    // Subscribe to the topic\n    pubsub.subscribe(\"my_topic\", |message| {\n        async {\n            // Print the received message\n            println!(\"Received message: {:?}\", message);\n\n            // Simulate some asynchronous work with the received message\n            tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;\n            println!(\"Finished processing message: {:?}\", message);\n\n            Ok(())\n        }\n    }).await?;\n\n    Ok(())\n}\n```\n\n## Contributing\n\nContributions are welcome! Please submit a pull request or create an issue to get started.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrempel%2Funisub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnrempel%2Funisub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrempel%2Funisub/lists"}