45 lines
721 B
Go
45 lines
721 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log"
|
||
|
|
||
|
"11-11.dev/goexamples/elasticstream"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
client, err := elasticstream.NewClient()
|
||
|
if err != nil {
|
||
|
log.Println("elasticstream.NewClient() err:", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
config := &elasticstream.Config{
|
||
|
Host: "http://localhost:9200",
|
||
|
Indexes: map[string]int{"users": 0, "students": 0, "teachers": 0},
|
||
|
BatchSize: 10,
|
||
|
}
|
||
|
|
||
|
err = client.Configure(config)
|
||
|
if err != nil {
|
||
|
log.Println("client.Configure() err:", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err = client.Open()
|
||
|
if err != nil {
|
||
|
log.Println("client.Open() err:", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
for {
|
||
|
data, err := client.Read()
|
||
|
if err != nil {
|
||
|
log.Println("eclient.Read() err:", err)
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
fmt.Println(data)
|
||
|
}
|
||
|
}
|