franz/consumer/topic_subscriber
Types
A builder for creating and configuring a Kafka topic subscriber.
pub opaque type Builder(callback_init_state)
Specifies which partitions to consume from.
pub type Partitions {
Partitions(List(Int))
All
}
Constructors
-
Partitions(List(Int))
Consume from specific partition numbers.
-
All
Consume from all available partitions.
pub type TopicSubscriber {
TopicSubscriber(name: process.Name(Message))
}
Constructors
-
TopicSubscriber(name: process.Name(Message))
Values
pub fn ack(cb_state: cb_state) -> Ack
Acknowledges the processing of a message. Use this in your callback to confirm message receipt.
pub fn named_client(
name: process.Name(Message),
) -> TopicSubscriber
pub fn new(
name name: process.Name(Message),
client client: franz.Client,
topic topic: String,
partitions partitions: Partitions,
message_type message_type: message_type.MessageType,
callback callback: fn(
Int,
franz.KafkaMessage,
callback_init_state,
) -> Ack,
init_callback_state init_callback_state: callback_init_state,
) -> Builder(callback_init_state)
Creates a new topic subscriber builder. The callback will be called for each message received from the topic partitions.
pub fn start(
builder: Builder(callback_init_state),
) -> Result(actor.Started(TopicSubscriber), actor.StartError)
Starts a new topic subscriber with the configured settings.
pub fn supervised(
builder: Builder(a),
) -> supervision.ChildSpecification(TopicSubscriber)
Creates a supervised worker for the topic subscriber. This can be used with Gleam’s OTP supervision trees to ensure the subscriber is restarted on failure.
pub fn with_commited_offset(
builder: Builder(callback_init_state),
partition partition: Int,
offset offset: Int,
) -> Builder(callback_init_state)
Adds a committed offset to the topic subscriber builder. CommittedOffsets are the offsets for the messages that have been successfully processed (acknowledged), not the begin-offset to start fetching from.
pub fn with_config(
builder: Builder(callback_init_state),
consumer_config: config.Config,
) -> Builder(callback_init_state)
Adds a consumer configuration option to the topic subscriber builder. Multiple configurations can be chained together.