broker/README.md

62 lines
2.2 KiB
Markdown
Raw Normal View History

2020-01-01 05:09:38 +00:00
## Broker - Front-end Real-time Message Broker
2019-12-16 18:04:14 +00:00
2020-01-01 05:09:38 +00:00
[![crates.io](https://meritbadge.herokuapp.com/broker)](https://crates.io/crates/broker)
2019-12-31 20:30:58 +00:00
2020-01-01 02:28:56 +00:00
### Purpose
2020-01-01 03:55:10 +00:00
The purpose of this library is to provide a real-time front-end message broker using SSE and a JSON API.
2020-01-01 02:28:56 +00:00
2020-01-01 05:09:38 +00:00
Broker is born from the need that rather than building a complex REST API with web-sockets to provide reactive web forms there is a simpler way.
2020-01-01 02:28:56 +00:00
2020-01-01 05:09:38 +00:00
Broker follows an insert-only/publish/subscribe paradigm rather than a REST CRUD paradigm.
2020-01-01 02:28:56 +00:00
2020-01-01 05:09:38 +00:00
In Broker you insert an event and its data via a JSON POST request (/insert). Broker publishes the latest event to an event stream via SSE (/events) and keeps all older versions in its database that can be viewed in a JSON GET request (/audit/{event}).
2020-01-01 02:28:56 +00:00
When the client first subscribes to the SSE connection (/events) all the latest events and data is sent to the client. Combined with sending the latest event via SSE when subscribed negates any necessity to do any GET API requests in the lifecycle of events.
The side-effect of this system is that the latest event is the schema. Old events are saved in the database and are not changed but the latest event is the schema for the front-end. This is pure NoSQL as the backend is agnostic to the event data.
2020-01-01 02:43:18 +00:00
### Features
2020-01-01 06:26:21 +00:00
* Real-time Event Stream via SSE
2020-01-01 06:24:50 +00:00
* CORS support
2020-01-01 02:43:18 +00:00
* Stateful immutable event persistence
* JSON POST API to insert events
* Sync latest events on client connection
* Audit log of event inserts
2020-01-01 02:28:56 +00:00
### Use
2019-12-16 18:04:14 +00:00
2019-12-31 20:29:09 +00:00
```rust
2020-01-01 05:09:38 +00:00
use broker::{broker_run};
2019-12-31 20:29:09 +00:00
#[actix_rt::main]
async fn main() -> std::result::Result<(), std::io::Error> {
2020-01-01 05:09:38 +00:00
broker_run("*".to_owned()).await
2019-12-31 20:29:09 +00:00
}
```
- the only param is the origin you want to allow - wildcard for all
- the PORT needs to passed in as an environment variable
2020-01-01 02:28:56 +00:00
### Example
2019-12-31 20:29:09 +00:00
2020-01-01 02:28:56 +00:00
- ``` make ```
- ``` make client ```
2019-12-16 18:04:14 +00:00
2020-01-01 02:28:56 +00:00
### Demo
2019-12-31 05:38:16 +00:00
2020-01-01 05:37:32 +00:00
- https://broker-demo.apibill.me
2020-01-01 03:55:10 +00:00
### Inspiration
* [React Hooks](https://reactjs.org/docs/hooks-intro.html)
* [Meteor](https://meteor.com)
* [MongoDB](https://www.mongodb.com/)
* [Pusher](https://pusher.com)
* [Event Sourcing](https://microservices.io/patterns/data/event-sourcing.html)
* [Best in Place](https://github.com/bernat/best_in_place)
* [Brock Whitten](https://www.youtube.com/watch?v=qljYMEfVukU)