franz/producer

Types

pub type Partitioner {
  PartitionFun(
    fn(String, Int, BitArray, BitArray) -> Result(Int, Nil),
  )
  Random
  Hash
}

Constructors

  • PartitionFun(
      fn(String, Int, BitArray, BitArray) -> Result(Int, Nil),
    )

    Partititoner function with Topic, PartitionCount, Key and Value that should return a partition number.

  • Random

    Random partitioner.

  • Hash

    Hash partititoner

pub opaque type ProducerBuilder
pub type ProducerPartition {
  Partition(Int)
  Partitioner(Partitioner)
}

Constructors

  • Partition(Int)
  • Partitioner(Partitioner)
pub type Value {
  Value(value: BitArray, headers: List(#(String, String)))
  ValueWithTimestamp(
    value: BitArray,
    timestamp: Int,
    headers: List(#(String, String)),
  )
}

Constructors

  • Value(value: BitArray, headers: List(#(String, String)))
  • ValueWithTimestamp(
      value: BitArray,
      timestamp: Int,
      headers: List(#(String, String)),
    )

Functions

pub fn new(client: FranzClient, topic: String) -> ProducerBuilder

Creates a new producer builder with the given Franz client and topic.

pub fn produce(
  client: FranzClient,
  topic: String,
  partition: ProducerPartition,
  key: BitArray,
  value: Value,
) -> Result(Nil, FranzError)

Produce one or more messages. A producer for the particular topic has to be already started (by calling producer.start()), unless you have specified AutoStartProducers(True) when starting the client.

pub fn produce_cb(
  client: FranzClient,
  topic: String,
  partition: ProducerPartition,
  key: BitArray,
  value: Value,
  callback: fn(Int, Int) -> a,
) -> Result(Int, FranzError)

This function will await the kafka ack before returning and calling the callback. A producer for the particular topic has to be already started (by calling producer.start()), unless you have specified AutoStartProducers(True) when starting the client. Returns the partititon of the produced message.

pub fn produce_sync(
  client: FranzClient,
  topic: String,
  partition: ProducerPartition,
  key: BitArray,
  value: Value,
) -> Result(Nil, FranzError)

This function will await the kafka ack before returning. A producer for the particular topic has to be already started (by calling producer.start()), unless you have specified AutoStartProducers(True) when starting the client.

pub fn produce_sync_offset(
  client: FranzClient,
  topic: String,
  partition: ProducerPartition,
  key: BitArray,
  value: Value,
) -> Result(Int, FranzError)

This function will await the kafka ack before returning. A producer for the particular topic has to be already started (by calling producer.start()), unless you have specified AutoStartProducers(True) when starting the client. This function will return the offset of the produced message.

pub fn start(builder: ProducerBuilder) -> Result(Nil, FranzError)

Start a producer with the given configuration. A producer for the particular topic has to be already started (by calling producer.start()), unless you have specified AutoStartProducers(True) when starting the client.

pub fn with_config(
  builder: ProducerBuilder,
  config: ProducerConfig,
) -> ProducerBuilder

Add a producer configuration to the producer builder.

Search Document