This commit is contained in:
crusader 2018-04-01 18:39:05 +09:00
parent 286a33acdb
commit 1fd01a35ad
4 changed files with 68 additions and 0 deletions

View File

@ -26,6 +26,26 @@
"wait": false "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": { "redis": {
"network": "tcp", "network": "tcp",
"addr": "192.168.1.50:6379", "addr": "192.168.1.50:6379",

23
external/kafka/client.go vendored Normal file
View 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
View 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)
}
}

View File

@ -4,3 +4,4 @@ import:
- package: git.loafle.net/overflow/overflow_gateway_websocket - package: git.loafle.net/overflow/overflow_gateway_websocket
subpackages: subpackages:
- server - server
- package: github.com/segmentio/kafka-go