Skip to content

Commit

Permalink
consumer(ticdc): modify kafka consumer (#11819)
Browse files Browse the repository at this point in the history
close #11818
  • Loading branch information
wk989898 authored Dec 5, 2024
1 parent 8f74dbc commit 4538839
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cmd/kafka-consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/pingcap/log"
"github.com/pingcap/tiflow/pkg/errors"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func getPartitionNum(o *option) (int32, error) {
Expand Down Expand Up @@ -99,6 +100,9 @@ func newConsumer(ctx context.Context, o *option) *consumer {
_ = configMap.SetKey("ssl.key.location", o.key)
_ = configMap.SetKey("ssl.certificate.location", o.cert)
}
if level, err := zapcore.ParseLevel(o.logLevel); err == nil && level.String() == "debug" {
configMap.SetKey("debug", "all")
}
client, err := kafka.NewConsumer(configMap)
if err != nil {
log.Panic("create kafka consumer failed", zap.Error(err))
Expand All @@ -121,6 +125,12 @@ func (c *consumer) Consume(ctx context.Context) {
}
}()
for {
select {
case <-ctx.Done():
log.Info("consumer exist: context cancelled")
return
default:
}
msg, err := c.client.ReadMessage(-1)
if err != nil {
log.Error("read message failed, just continue to retry", zap.Error(err))
Expand Down
3 changes: 0 additions & 3 deletions cmd/kafka-consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/url"
"os"
"os/signal"
"runtime/debug"
"strings"
"sync"
"syscall"
Expand All @@ -35,8 +34,6 @@ import (
)

func main() {
debug.SetMemoryLimit(14 * 1024 * 1024 * 1024)

var (
upstreamURIStr string
configFile string
Expand Down

0 comments on commit 4538839

Please sign in to comment.