Skip to content

Commit b983a48

Browse files
committed
Add support for deferred publishing via Client (HTTP)
1 parent c499ac7 commit b983a48

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

nsq.go

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"io/ioutil"
77
"net/http"
88
"net/url"
9+
"strconv"
10+
"time"
911

1012
"github.com/pkg/errors"
1113
)
@@ -28,6 +30,16 @@ func (c *Client) Publish(topic string, message []byte) (err error) {
2830
return
2931
}
3032

33+
func (c *Client) DeferredPublish(topic string, delay time.Duration, message []byte) (err error) {
34+
delayStr := strconv.FormatUint(uint64(delay/time.Millisecond), 10)
35+
36+
_, err = c.do("POST", "/pub", url.Values{
37+
"topic": []string{topic},
38+
"defer": []string{delayStr},
39+
}, message)
40+
return
41+
}
42+
3143
func (c *Client) MutliPublish(topic string, messages ...[]byte) (err error) {
3244
_, err = c.do("POST", "/mpub", url.Values{
3345
"topic": []string{topic},

0 commit comments

Comments
 (0)