@@ -34,8 +34,11 @@ type Target struct {
34
34
// Map of target topics and their config.
35
35
targetTopics Topics
36
36
37
- batchCh chan * kgo.Record
38
- batch []* kgo.Record
37
+ // Inlet receives relayed messages into target for batching
38
+ inletCh chan * kgo.Record
39
+
40
+ // Holds the active batch that is produced to destination topic
41
+ batch []* kgo.Record
39
42
}
40
43
41
44
// NewTarget returns a new producer relay that handles target Kafka instances.
@@ -49,7 +52,7 @@ func NewTarget(globalCtx context.Context, cfg TargetCfg, pCfg ProducerCfg, topic
49
52
targetTopics : topics ,
50
53
51
54
batch : make ([]* kgo.Record , 0 , pCfg .BatchSize ),
52
- batchCh : make (chan * kgo.Record ),
55
+ inletCh : make (chan * kgo.Record , pCfg . BatchSize * 10 ),
53
56
}
54
57
55
58
// Initialize the actual Kafka client.
@@ -73,12 +76,12 @@ func (tg *Target) Close() {
73
76
74
77
// CloseBatchCh closes the Producer batch channel.
75
78
func (tg * Target ) CloseBatchCh () {
76
- close (tg .batchCh )
79
+ close (tg .inletCh )
77
80
}
78
81
79
82
// GetBatchCh returns the Producer batch channel.
80
83
func (tg * Target ) GetBatchCh () chan * kgo.Record {
81
- return tg .batchCh
84
+ return tg .inletCh
82
85
}
83
86
84
87
// prepareRecord checks if custom topic partition mapping is defined.
@@ -111,7 +114,7 @@ func (tg *Target) Start(ctx context.Context) error {
111
114
return ctx .Err ()
112
115
113
116
// Queue the message to and flush if the batch size is reached.
114
- case msg , ok := <- tg .batchCh :
117
+ case msg , ok := <- tg .inletCh :
115
118
if ! ok {
116
119
// Flush and cleanup on exit.
117
120
if err := tg .drain (); err != nil {
@@ -246,7 +249,7 @@ outerLoop:
246
249
// drain drains and flushes any pending messages in the producer.
247
250
func (tg * Target ) drain () error {
248
251
now := time .Now ()
249
- for rec := range tg .batchCh {
252
+ for rec := range tg .inletCh {
250
253
tg .prepareRecord (rec )
251
254
tg .batch = append (tg .batch , rec )
252
255
}
0 commit comments