Documentation
¶
Overview ¶
Package kafka implements the messaging interfaces against a Kafka broker.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotConsumer = errors.New("client is not configured to consume")
ErrNotConsumer is returned by the consumer methods on a Client that was not built with WithConsumerGroup.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements messaging.Publisher, and additionally messaging.Consumer when constructed with WithConsumerGroup.
func NewClient ¶
NewClient connects to the brokers at brokerAddresses.
Producing is idempotent by default in franz-go: the broker discards a duplicate caused by a retried produce request. Note this only spans a single producer session — it is not protection against the application publishing the same event again after a restart, which is what event.Event.ID is for.
func (*Client) Poll ¶
Poll blocks until at least one event is available, ctx is cancelled, or the Client is closed.
func (*Client) Publish ¶
Publish writes the event synchronously and returns once the brokers have acknowledged it.
The event key becomes the record key, which is what determines the partition and therefore the ordering guarantee: events sharing a key land on the same partition and are consumed in publish order.
type Option ¶
type Option func(*options)
Option configures a Client.
func WithConsumerGroup ¶
WithConsumerGroup makes the Client a member of the named consumer group, subscribed to topics.
Partitions are shared among the members of a group, so scaling a group beyond the partition count leaves the extra members idle. Independent groups each receive the full stream, which is how one topic fans out to several services.
Auto-committing is disabled: offsets advance only when Commit is called, so an event is redelivered if the process dies before it is processed.