From aaa2778d27ad8467d7f84be34442bb03b7b84054 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Fri, 18 Mar 2022 12:36:36 +0700 Subject: [PATCH] [Update] Add sync data with jetstream --- elasticsearch.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/elasticsearch.go b/elasticsearch.go index ac2ba6b..1c3d6dc 100644 --- a/elasticsearch.go +++ b/elasticsearch.go @@ -40,6 +40,29 @@ func NewClient(config Config) (*Client, error) { // SyncData // Sync data to services ES func (c *Client) SyncData(data SyncData) (bool, error) { + var ( + req = RequestBody{ + ApiKey: c.Config.ApiKey, + Body: toBytes(data), + } + res *Response + ) + msg, err := c.natsServer.Request(SubjectSyncData, toBytes(req)) + if err != nil { + return false, err + } + if err = json.Unmarshal(msg.Data, &res); err != nil { + return false, err + } + if res.Message != "" { + return false, errors.New(res.Message) + } + return res.Success, nil +} + +// SyncDataWithJetStream +// Sync data to services ES with JetStream +func (c *Client) SyncDataWithJetStream(data SyncData) (bool, error) { var ( req = RequestBody{ ApiKey: c.Config.ApiKey, @@ -50,6 +73,7 @@ func (c *Client) SyncData(data SyncData) (bool, error) { if err != nil { return false, err } + return true, nil } -- 2.34.1