增加分区参数
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
./proxy
|
proxy
|
||||||
@@ -36,6 +36,8 @@ var (
|
|||||||
space = []byte{' '}
|
space = []byte{' '}
|
||||||
addr = flag.String("addr", ":9000", "http service address")
|
addr = flag.String("addr", ":9000", "http service address")
|
||||||
bootstrapServers = flag.String("bootstrap-servers", "localhost:9092", "kafka bootstrap servers")
|
bootstrapServers = flag.String("bootstrap-servers", "localhost:9092", "kafka bootstrap servers")
|
||||||
|
partition = flag.Int("partition", 0, "kafka tipic partion")
|
||||||
|
wait = flag.Duration("graceful-timeout", time.Second*15, "the duration for which the server gracefully wait for existing connections to finish - e.g. 15s or 1m")
|
||||||
upgrader = websocket.Upgrader{
|
upgrader = websocket.Upgrader{
|
||||||
ReadBufferSize: 1024,
|
ReadBufferSize: 1024,
|
||||||
WriteBufferSize: 1024,
|
WriteBufferSize: 1024,
|
||||||
@@ -90,18 +92,10 @@ func (c *Client) readPump(topic string) {
|
|||||||
})
|
})
|
||||||
reader.SetOffset(-1) //lastoffset
|
reader.SetOffset(-1) //lastoffset
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// // fmt.Fprintf(os.Stderr, "Failed to create consumer: %s\n", err)
|
|
||||||
// log.WithError(err).Fatal("Failed to create consumer")
|
|
||||||
// os.Exit(1)
|
|
||||||
// }
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"reader": reader,
|
"reader": reader,
|
||||||
}).Info("Created ")
|
}).Info("Created ")
|
||||||
|
|
||||||
// consumer.SubscribeTopics([]string{topic}, nil)
|
|
||||||
|
|
||||||
run := true
|
run := true
|
||||||
|
|
||||||
for run == true {
|
for run == true {
|
||||||
@@ -111,37 +105,17 @@ func (c *Client) readPump(topic string) {
|
|||||||
run = false
|
run = false
|
||||||
log.Fatal("break ")
|
log.Fatal("break ")
|
||||||
default:
|
default:
|
||||||
// ev := consumer.Poll(100)
|
|
||||||
// if ev == nil {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// switch e := ev.(type) {
|
|
||||||
// case *kafka.Message:
|
|
||||||
// log.WithFields(log.Fields{"partition": e.TopicPartition, "message": string(e.Value)}).Info("got message")
|
|
||||||
// c.hub.broadcast <- e.Value
|
|
||||||
// if e.Headers != nil {
|
|
||||||
// log.WithFields(log.Fields{"header": e.Headers}).Info(" with header")
|
|
||||||
// }
|
|
||||||
// case kafka.Error:
|
|
||||||
// // Errors should generally be considered as informational, the client will try to automatically recover
|
|
||||||
// log.WithFields(log.Fields{"error": e}).Error("got error")
|
|
||||||
// default:
|
|
||||||
// log.WithFields(log.Fields{"event": e}).Info("ignored")
|
|
||||||
// }
|
|
||||||
for {
|
for {
|
||||||
m, err := reader.ReadMessage(context.Background())
|
m, err := reader.ReadMessage(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{"error": err}).Error("read error")
|
log.WithFields(log.Fields{"error": err}).Error("read error")
|
||||||
}
|
}
|
||||||
// fmt.Printf("message at offset %d: %s = %s\n", m.Offset, string(m.Key), string(m.Value))
|
|
||||||
log.WithFields(log.Fields{"offset": m.Offset, "message": string(m.Value)}).Info("got message")
|
log.WithFields(log.Fields{"offset": m.Offset, "message": string(m.Value)}).Info("got message")
|
||||||
c.hub.broadcast <- m.Value
|
c.hub.broadcast <- m.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// consumer.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// writePump pumps messages from the hub to the websocket connection.
|
// writePump pumps messages from the hub to the websocket connection.
|
||||||
@@ -258,8 +232,6 @@ func (h *Hub) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var wait time.Duration
|
|
||||||
flag.DurationVar(&wait, "graceful-timeout", time.Second*15, "the duration for which the server gracefully wait for existing connections to finish - e.g. 15s or 1m")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
|
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
|
||||||
@@ -295,7 +267,7 @@ func main() {
|
|||||||
<-c
|
<-c
|
||||||
|
|
||||||
// Create a deadline to wait for.
|
// Create a deadline to wait for.
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), wait)
|
ctx, cancel := context.WithTimeout(context.Background(), *wait)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
// Doesn't block if no connections, but will otherwise wait
|
// Doesn't block if no connections, but will otherwise wait
|
||||||
// until the timeout deadline.
|
// until the timeout deadline.
|
||||||
|
|||||||
Reference in New Issue
Block a user