Documentation ¶
Overview ¶
Package kafka provides a Gnomock Preset for Kafka.
Index ¶
Constants ¶
const ( BrokerPort = "broker" ZooKeeperPort = "zookeeper" WebPort = "web" SchemaRegistryPort = "registry" )
The following ports are exposed by this preset:.
Variables ¶
This section is empty.
Functions ¶
func Preset ¶
Preset creates a new Gmomock Kafka preset. This preset includes a Kafka specific healthcheck function and default Kafka image and ports.
Kafka preset uses a constant broker port number (49092) instead of allocating a random unoccupied port on every run. Please make sure this port is available when using this preset.
By default, this preset uses `lensesio/fast-data-dev` docker image with version `2.5.1-L0` (version can be changed using `WithVersion`).
Types ¶
type Message ¶
type Message struct { Topic string `json:"topic"` Key string `json:"key"` Value string `json:"value"` Time int64 `json:"time"` }
Message is a single message sent to Kafka.
type Option ¶
type Option func(*P)
Option is an optional configuration of this Gnomock preset. Use available Options to configure the container.
func WithMessages ¶
WithMessages makes sure that these messages can be consumed during the test once the container is ready.
func WithMessagesFile ¶
WithMessagesFile allows to load messages to be sent into Kafka from one or multiple files.
func WithSchemaRegistry ¶ added in v0.22.0
func WithSchemaRegistry() Option
WithSchemaRegistry makes the container wait for the schema registry port to become available. Note that it takes longer to setup schema registry than the broker itself. Gnomock will not wait for the registry by default, but it may become available eventually.
func WithTopicConfigs ¶ added in v0.31.0
func WithTopicConfigs(topics ...TopicConfig) Option
WithTopicConfigs makes sure that the provided topics with the given configs are available when Kafka is up and running. Unlike WithTopics, this allows to also set partition count. Both topics from WithTopics and WithTopicConfigs will be added to Kafka.
func WithTopics ¶
WithTopics makes sure that the provided topics are available when Kafka is up and running. Both topics from WithTopics and WithTopicConfigs will be added to Kafka.
type P ¶
type P struct { Version string `json:"version"` Topics []string `json:"topics"` Messages []Message `json:"messages"` MessagesFiles []string `json:"messages_files"` UseSchemaRegistry bool `json:"use_schema_registry"` TopicConfigs []TopicConfig `json:"topic_configs"` }
P is a Gnomock Preset implementation of Kafka.
func (*P) Ports ¶
func (p *P) Ports() gnomock.NamedPorts
Ports returns ports that should be used to access this container.