ing
This commit is contained in:
parent
286a33acdb
commit
1fd01a35ad
20
config.json
20
config.json
|
@ -26,6 +26,26 @@
|
|||
"wait": false
|
||||
}
|
||||
},
|
||||
"kafka": {
|
||||
"producers": {
|
||||
"metric": {
|
||||
"brokers": [
|
||||
"192.168.1.50:9092",
|
||||
"192.168.1.50:9093",
|
||||
"192.168.1.50:9094"
|
||||
],
|
||||
"topic": "metric"
|
||||
},
|
||||
"meta": {
|
||||
"brokers": [
|
||||
"192.168.1.50:9092",
|
||||
"192.168.1.50:9093",
|
||||
"192.168.1.50:9094"
|
||||
],
|
||||
"topic": "meta"
|
||||
}
|
||||
}
|
||||
},
|
||||
"redis": {
|
||||
"network": "tcp",
|
||||
"addr": "192.168.1.50:6379",
|
||||
|
|
23
external/kafka/client.go
vendored
Normal file
23
external/kafka/client.go
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
package kafka
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/segmentio/kafka-go"
|
||||
)
|
||||
|
||||
func Send(key []byte, value []byte) error {
|
||||
if nil == kafkaWriter {
|
||||
return fmt.Errorf("Kafka client is not valid")
|
||||
}
|
||||
|
||||
err := kafkaWriter.WriteMessages(context.Background(),
|
||||
kafka.Message{
|
||||
Key: key,
|
||||
Value: value,
|
||||
},
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
24
external/kafka/kafka.go
vendored
Normal file
24
external/kafka/kafka.go
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
package kafka
|
||||
|
||||
import (
|
||||
"git.loafle.net/commons_go/logging"
|
||||
"github.com/segmentio/kafka-go"
|
||||
)
|
||||
|
||||
var (
|
||||
kafkaWriter *kafka.Writer
|
||||
)
|
||||
|
||||
func ExternalInit() {
|
||||
kafkaWriter = kafka.NewWriter(kafka.WriterConfig{
|
||||
Brokers: []string{"192.168.1.50:9092"},
|
||||
Topic: "topic-overflow-probe-metric",
|
||||
Balancer: &kafka.LeastBytes{},
|
||||
})
|
||||
}
|
||||
|
||||
func ExternalDestroy() {
|
||||
if err := kafkaWriter.Close(); nil != err {
|
||||
logging.Logger().Errorf("%v", err)
|
||||
}
|
||||
}
|
|
@ -4,3 +4,4 @@ import:
|
|||
- package: git.loafle.net/overflow/overflow_gateway_websocket
|
||||
subpackages:
|
||||
- server
|
||||
- package: github.com/segmentio/kafka-go
|
||||
|
|
Loading…
Reference in New Issue
Block a user