Skip to content

vegris/pachka

Repository files navigation

Pachka

Hex.pm Version Documentation CI Coverage Status

Pachka is a message batching library for Elixir.

It provides a reliable way to collect messages and deliver them in batches to configurable destinations. Messages are buffered until either the batch size limit is reached or the batch timeout occurs. Failed deliveries are automatically retried with configurable backoff strategies.

Features

  • Configurable batch sizes and timeouts
  • Customizable message sinks for different delivery targets
  • Automatic retries with customizable backoff
  • Overload protection with queue size limits
  • Graceful shutdown with message draining

Installation

def deps do
  [
    {:pachka, "~> 1.0.0"}
  ]
end

Usage

  1. Define a sink module that implements the Pachka.Sink behavior:
defmodule MyApp.MessageSink do
  @behaviour Pachka.Sink
  
  @impl true
  def send_batch(messages, _server_value) do
    # Process messages in batch
    :ok
  end
end
  1. Start Pachka server:
{:ok, pid} = Pachka.start_link(
  name: MyPachka,
  sink: MyApp.MessageSink,
  max_batch_size: 100,
  max_batch_delay: :timer.seconds(1)
)
  1. Send messages:
:ok = Pachka.send_message(MyPachka, %{event: "user_login"})
:ok = Pachka.send_message(MyPachka, %{event: "page_view"})

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

About

Message batching library for Elixir applications

Resources

License

Stars

Watchers

Forks

Languages