2016-05-17 15:13:32 +00:00
|
|
|
package subscriber
|
|
|
|
|
|
|
|
import (
|
2016-05-17 19:24:23 +00:00
|
|
|
"time"
|
|
|
|
|
2016-05-17 15:13:32 +00:00
|
|
|
"github.com/influxdata/influxdb/client/v2"
|
|
|
|
"github.com/influxdata/influxdb/coordinator"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HTTP supports writing points over HTTP using the line protocol.
|
|
|
|
type HTTP struct {
|
|
|
|
c client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewHTTP returns a new HTTP points writer with default options.
|
2016-05-17 19:36:03 +00:00
|
|
|
func NewHTTP(addr string, timeout time.Duration) (*HTTP, error) {
|
2016-05-17 15:13:32 +00:00
|
|
|
conf := client.HTTPConfig{
|
2016-05-17 19:24:23 +00:00
|
|
|
Addr: addr,
|
2016-05-17 19:36:03 +00:00
|
|
|
Timeout: timeout,
|
2016-05-17 15:13:32 +00:00
|
|
|
}
|
|
|
|
c, err := client.NewHTTPClient(conf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &HTTP{c: c}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WritePoints writes points over HTTP transport.
|
|
|
|
func (h *HTTP) WritePoints(p *coordinator.WritePointsRequest) (err error) {
|
|
|
|
bp, _ := client.NewBatchPoints(client.BatchPointsConfig{
|
|
|
|
Database: p.Database,
|
|
|
|
RetentionPolicy: p.RetentionPolicy,
|
|
|
|
})
|
|
|
|
for _, p := range p.Points {
|
|
|
|
bp.AddPoint(client.NewPointFrom(p))
|
|
|
|
}
|
|
|
|
err = h.c.Write(bp)
|
|
|
|
return
|
|
|
|
}
|