[Update] Add sync data with jetstream

This commit is contained in:
trunglt251292 2022-03-18 12:36:36 +07:00
parent bded4de2eb
commit aaa2778d27
1 changed files with 24 additions and 0 deletions

View File

@ -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
}