-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.go
37 lines (33 loc) · 1.07 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2022 coffeehaze. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package oni
import (
"github.com/segmentio/kafka-go"
"net"
"time"
)
// BatchTimeoutWriter template
// message was sent will consume after duration defined
// with default round-robin balancer and require ack 0
// which means message do not wait for acknowledgement
// highly recommended when for send message to retry topic
// to avoid fast ping-pong effect between main and retry topic
func BatchTimeoutWriter(addr net.Addr, topic string, duration time.Duration) *kafka.Writer {
return &kafka.Writer{
Addr: addr,
Topic: topic,
BatchTimeout: duration,
}
}
// BasicWriter template
// message was sent directly to given topic name with
// default round-robin balancer and require ack 0 which
// means message do not wait for acknowledgement
// highly recommended for send basic message to topic
func BasicWriter(addr net.Addr, topic string) *kafka.Writer {
return &kafka.Writer{
Addr: addr,
Topic: topic,
}
}