change publish payload data type to []byte

This commit is contained in:
Nam Huynh 2021-11-30 22:29:02 +07:00
parent 27a0bb627d
commit 374a616387
1 changed files with 2 additions and 4 deletions

View File

@ -1,7 +1,6 @@
package natsio package natsio
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -9,11 +8,10 @@ import (
) )
// Publish ... // Publish ...
func Publish(stream, subject string, data interface{}) error { func Publish(stream, subject string, payload []byte) error {
channel := combineStreamAndSubjectName(stream, subject) channel := combineStreamAndSubjectName(stream, subject)
b, _ := json.Marshal(data) _, err := natsJS.PublishAsync(channel, payload)
_, err := natsJS.PublishAsync(channel, b)
if err != nil { if err != nil {
msg := fmt.Sprintf("publish message to subject %s error: %s", channel, err.Error()) msg := fmt.Sprintf("publish message to subject %s error: %s", channel, err.Error())
return errors.New(msg) return errors.New(msg)