kafkaclient

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 4 Imported by: 0

README

kafkaclient

Golang kafka package to simplify te consumer and producer usage

Install

go get github.com/san-services/kafkaclient

Consumer

func onMessageReceived(topic string, message string){
  // do stuff with message
}


// listen to test topic
client := kafkaclient.New("localhost:9092", "group1", onMessageReceived)
go client.ListenToTopic(context.Background(), "test")

Producer

client := kafkaclient.New("localhost:9092", "producerGroup", nil)

// produce message to test topic
err := client.ProduceToTopic("test", "this is a test message")

if err != nil {
  // handle error...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KafkaClient

type KafkaClient struct {
	Server            string
	GroupID           string
	OnMessageReceived onMessage
}

KafkaClient ...

func New

func New(server string, groupID string, onMessageReceived onMessage) *KafkaClient

New creates broker object

func (*KafkaClient) ListenToTopic

func (kc *KafkaClient) ListenToTopic(ctx context.Context, topic string)

ListenToTopic starts listening for the specified topic

func (*KafkaClient) ProduceToTopic

func (kc *KafkaClient) ProduceToTopic(ctx context.Context, topic string, message string) error

ProduceToTopic Sends a message to the specified topic

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL