An open API service indexing awesome lists of open source software.

https://github.com/michalmuskala/persist

GenStage-based persistence layer guaranteeing at-least-once delivery of the events.
https://github.com/michalmuskala/persist

Last synced: 5 months ago
JSON representation

GenStage-based persistence layer guaranteeing at-least-once delivery of the events.

Awesome Lists containing this project

README

        

# Persist

GenStage-based persistence layer guaranteeing at-least-once delivery of the
events.

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:

1. Add `persist` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:persist, "~> 0.1.0"}]
end
```

2. Ensure `persist` is started before your application:

```elixir
def application do
[applications: [:persist]]
end
```

If [published on HexDocs](https://hex.pm/docs/tasks#hex_docs), the docs can
be found at [https://hexdocs.pm/persist](https://hexdocs.pm/persist)

## Usage

```elixir
{:ok, _} = Persist.start_link(EventBus, path: "./data")

# Insert some events into the EventBus
{:ok, producer} = GenStage.from_enumerable(1..1000)
GenStage.sync_subscribe(Persist.consumer(EventBus), to: producer)

# Consume the events
GenStage.stream([Persist.producer(EventBus, :my_subscription)])
|> Enum.each(fn {ack_ref, event} ->
Persist.ack(ack_ref)
IO.inspect event
end)
```