Skip to content

ivan-p-nikolov/kafka-client-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kafka-client-go

CircleCI Go Report Card Coverage Status

Library for producing and consuming messages directly from Kafka.

To use

To import:

import "github.com/Financial-Times/kafka-client-go/kafka"

Producer

To set up, create your producer:

kp, err := kafka.NewProducer(*kafkaAddresses, *kafkaTopic)

You can then send an FT Message:

message := kafka.NewFTMessage(map[string]string{}, string(concept))
err = kp.SendMessage(message)

Consumer

Create the consumer and start listening:

kc, err := kafka.NewConsumer(*zookeeperConnectionString, *groupName, []string{*topic})
kc.StartListening(handler.ProcessKafkaMessage)

Make sure to close it when the app is shutting down.

kc.Shutdown()

Perseverant Implementations

The library also provides perseverant implementations of the Consumer and Producer interfaces. These keep trying to establish connections to Kafka and Zookeeper until successful. Attempting to consume or produce messages, or calling the connectivity check methods, will fail if no connection has yet been established.

Testing

Some tests in this project require a local Zookeeper (port 2181) / Kafka (port 9092). To omit these tests, use the -short option.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%