mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
update imports
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
[](https://www.codetriage.com/gogf/gf)
|
||||
-->
|
||||
|
||||
`GF(Go Frame)`是一款模块化、松耦合、生产级、实战化的Go应用开发框架。提供了常用的核心开发组件,如:缓存、日志、文件、时间、队列、数组、集合、字符串、定时器、命令行、文件锁、内存锁、对象池、连接池、数据校验、数据编码、文件监控、定时任务、数据库ORM、TCP/UDP组件、进程管理/通信、
|
||||
`GF(Go Frame)`是一款模块化、松耦合、生产级Go应用开发框架。提供了常用的核心开发组件,如:缓存、日志、文件、时间、队列、数组、集合、字符串、定时器、命令行、文件锁、内存锁、对象池、连接池、数据校验、数据编码、文件监控、定时任务、数据库ORM、TCP/UDP组件、进程管理/通信、
|
||||
并发安全容器等等。并提供了Web服务开发的系列核心组件,如:Router、Cookie、Session、服务注册、配置管理、模板引擎等等,支持热重启、热更新、多域名、多端口、多服务、HTTPS、Rewrite等特性。
|
||||
|
||||
|
||||
|
||||
@ -1,97 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/gogf/gf/third/github.com/Shopify/sarama"
|
||||
"github.com/gogf/gf/third/github.com/bsm/sarama-cluster"
|
||||
)
|
||||
|
||||
var (
|
||||
groupID = flag.String("group", "", "REQUIRED: The shared consumer group name")
|
||||
brokerList = flag.String("brokers", os.Getenv("KAFKA_PEERS"), "The comma separated list of brokers in the Kafka cluster")
|
||||
topicList = flag.String("topics", "", "REQUIRED: The comma separated list of topics to consume")
|
||||
offset = flag.String("offset", "newest", "The offset to start with. Can be `oldest`, `newest`")
|
||||
verbose = flag.Bool("verbose", false, "Whether to turn on sarama logging")
|
||||
|
||||
logger = log.New(os.Stderr, "", log.LstdFlags)
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *groupID == "" {
|
||||
printUsageErrorAndExit("You have to provide a -group name.")
|
||||
} else if *brokerList == "" {
|
||||
printUsageErrorAndExit("You have to provide -brokers as a comma-separated list, or set the KAFKA_PEERS environment variable.")
|
||||
} else if *topicList == "" {
|
||||
printUsageErrorAndExit("You have to provide -topics as a comma-separated list.")
|
||||
}
|
||||
|
||||
// Init config
|
||||
config := cluster.NewConfig()
|
||||
if *verbose {
|
||||
sarama.Logger = logger
|
||||
} else {
|
||||
config.Consumer.Return.Errors = true
|
||||
config.Group.Return.Notifications = true
|
||||
}
|
||||
|
||||
switch *offset {
|
||||
case "oldest":
|
||||
config.Consumer.Offsets.Initial = sarama.OffsetOldest
|
||||
case "newest":
|
||||
config.Consumer.Offsets.Initial = sarama.OffsetNewest
|
||||
default:
|
||||
printUsageErrorAndExit("-offset should be `oldest` or `newest`")
|
||||
}
|
||||
|
||||
// Init consumer, consume errors & messages
|
||||
consumer, err := cluster.NewConsumer(strings.Split(*brokerList, ","), *groupID, strings.Split(*topicList, ","), config)
|
||||
if err != nil {
|
||||
printErrorAndExit(69, "Failed to start consumer: %s", err)
|
||||
}
|
||||
defer consumer.Close()
|
||||
|
||||
// Create signal channel
|
||||
sigchan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigchan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
// Consume all channels, wait for signal to exit
|
||||
for {
|
||||
select {
|
||||
case msg, more := <-consumer.Messages():
|
||||
if more {
|
||||
fmt.Fprintf(os.Stdout, "%s/%d/%d\t%s\n", msg.Topic, msg.Partition, msg.Offset, msg.Value)
|
||||
consumer.MarkOffset(msg, "")
|
||||
}
|
||||
case ntf, more := <-consumer.Notifications():
|
||||
if more {
|
||||
logger.Printf("Rebalanced: %+v\n", ntf)
|
||||
}
|
||||
case err, more := <-consumer.Errors():
|
||||
if more {
|
||||
logger.Printf("Error: %s\n", err.Error())
|
||||
}
|
||||
case <-sigchan:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printErrorAndExit(code int, format string, values ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: "+format+"\n\n", values...)
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func printUsageErrorAndExit(format string, values ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: "+format+"\n\n", values...)
|
||||
flag.Usage()
|
||||
os.Exit(64)
|
||||
}
|
||||
Reference in New Issue
Block a user