-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78995b8
commit 8c1f146
Showing
7 changed files
with
201 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package franz | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/twmb/franz-go/pkg/kgo" | ||
) | ||
|
||
type Producer struct { | ||
BootstrapServers []string | ||
wg *sync.WaitGroup | ||
instance *kgo.Client | ||
} | ||
|
||
func NewProducer(bootstrapServers string) *Producer { | ||
brokers := strings.Split(bootstrapServers, ",") | ||
instance, err := kgo.NewClient(kgo.SeedBrokers(brokers...)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
producer := &Producer{BootstrapServers: brokers, wg: &sync.WaitGroup{}, instance: instance} | ||
|
||
return producer | ||
} | ||
|
||
func (p *Producer) Produce(topic string, key string, value string) { | ||
p.instance.ProduceSync(context.Background(), &kgo.Record{Topic: topic, Key: []byte(key), Value: []byte(value)}) | ||
} | ||
|
||
func (p *Producer) ProduceChannel(topic string, key string, value string) { | ||
p.wg.Add(1) | ||
p.instance.Produce(context.Background(), &kgo.Record{Topic: topic, Key: []byte(key), Value: []byte(value)}, p.DeliveryReport) | ||
} | ||
|
||
func (p *Producer) DeliveryReport(_ *kgo.Record, _ error) { | ||
p.wg.Done() | ||
} | ||
|
||
func (p *Producer) Wait() { | ||
p.wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package goka | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/lovoo/goka" | ||
"github.com/lovoo/goka/codec" | ||
) | ||
|
||
type Producer struct { | ||
BootstrapServers []string | ||
wg *sync.WaitGroup | ||
instance *goka.Emitter | ||
} | ||
|
||
func NewProducer(bootstrapServers string, topic string) *Producer { | ||
brokers := strings.Split(bootstrapServers, ",") | ||
emitter, err := goka.NewEmitter(brokers, goka.Stream(topic), new(codec.String)) | ||
if err != nil { | ||
log.Fatalf("error creating emitter: %v", err) | ||
} | ||
|
||
producer := &Producer{BootstrapServers: brokers, wg: &sync.WaitGroup{}, instance: emitter} | ||
|
||
return producer | ||
} | ||
|
||
func (p *Producer) Produce(key string, value string) { | ||
p.instance.EmitSync(key, value) | ||
} | ||
|
||
func (p *Producer) ProduceChannel(key string, value string) { | ||
p.wg.Add(1) | ||
promise, err := p.instance.Emit(key, value) | ||
if err != nil { | ||
p.wg.Done() | ||
return | ||
} | ||
|
||
promise.Then(p.DeliveryReport) | ||
} | ||
|
||
func (p *Producer) DeliveryReport(err error) { | ||
defer p.wg.Done() | ||
} | ||
|
||
func (p *Producer) Wait() { | ||
p.wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package kafkaclients | ||
package kafkaclient | ||
|
||
const ( | ||
// 1 KB | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package kafkaclients | ||
package kafkaclient | ||
|
||
import "fmt" | ||
|
||
|