Galena

hex.pmhexdocs.pmBuild Status

Galena is a topic producer-consumer library built on top of GenStage for Elixir.

I highly recommend to initiate your producers/consumers under a Supervisor.

Installation

If available in Hex, the package can be installed as:

Definition

  defmodule MyProducer do
    use Galena.Producer

    def handle_produce({topic, data}) do
      {topic, data}
    end
  end
  defmodule MyProducerConsumer do
    use Galena.ProducerConsumer
  
    def handle_produce(topic, data) do
      result_topic = topic <> Integer.to_string(:rand.uniform(2))
      {result_topic, "modified by producer-consumer: " <> data}
    end
  end
  # Example
  args = [
    producers_info: [
      {["topic_1", "topic_2", "topic_3"], :producer1},
      {["topic_A"], :producer2},
      {["topic_a", "topic_b"], :producer3},
      {[], :producer4}
    ]
  ]
  defmodule MyConsumer do
    use Galena.Consumer
  
    def handle_consume(topic, message) do
      IO.puts(topic <> ": " <> message)
    end
  end
 

Running

Test