Unisub
Unisub 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.
Features
- Publish messages to topics
- Subscribe to topics to receive messages
- Create and remove topics
- Includes a convenience binary for managing topics and running migrations
- Asynchronous design using Tokio
Installation
Add Unisub as a dependency in your Cargo.toml:
[]
= "*"
Setting up the Postgres Environment
- Install Postgres if you haven't already. You can download it from here.
- Create a new database and note the connection URL.
- Make sure your Postgres database is accessible and running.
Environment Variable
Set an environment variable called DATABASE_URL with the Postgres connection URL.
Running Migrations and Setting Up Topics
Using CLI
First, run the migrations:
Then you can add your topics:
Programmatically
use PubSub;
use migrate;
use PgPool;
async
Usage
Library
use PubSub;
use PgPool;
async
And here's an example of how to subscribe to a topic:
use PubSub;
use PgPool;
async
Contributing
Contributions are welcome! Please submit a pull request or create an issue to get started.
License
This project is licensed under the MIT License.