BroadwayPgQue (broadway_pgque v0.1.0)

Copy Markdown View Source

Broadway producer for PgQue, a high-throughput, zero-bloat Postgres queue engine.

Example Usage

Add BroadwayPgQue.Producer to your Broadway pipeline:

defmodule MyPipeline do
  use Broadway

  alias BroadwayPgQue.Producer, as: PgQueProducer

  def start_link(_opts) do
    Broadway.start_link(__MODULE__,
      name: __MODULE__,
      producer: [
        module: {
          PgQueProducer,
          repo: MyApp.Repo,
          queue: "notifications",
          concurrency: 1
        }
      ],
      processors: [
        default: [concurrency: 10]
      ],
      batchers: [
        default: [batch_size: 50, batch_timeout: 1000]
      ]
    )
  end

  @impl true
  def handle_message(_processor, message, _context) do
    # message.data contains the payload
    # message.metadata contains :id, :batch_id, :type, :retry_count, etc.
    message
  end
end

Instant Wake Up

When enqueuing events in PostgreSQL, you can immediately wake up the Broadway producer (bypassing any idle poll interval):

BroadwayPgQue.wake_up(MyPipeline)

Summary

Functions

Sends a :wake_up message to all producer processes of the given Broadway pipeline.

Functions

wake_up(pipeline_name)

@spec wake_up(atom() | pid()) :: :ok

Sends a :wake_up message to all producer processes of the given Broadway pipeline.