Skip to content

Commit

Permalink
Expose DeferredPublish command on producer
Browse files Browse the repository at this point in the history
Since a producer doesn't expose it's conn or send command
method, it might be beneficial to add helper functions for producer
related commands like DeferredPublish
  • Loading branch information
DanielHeckrath committed Sep 29, 2015
1 parent dcc251c commit b9b62d3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,26 @@ func (w *Producer) MultiPublish(topic string, body [][]byte) error {
return w.sendCommand(cmd)
}

// DeferredPublish synchronously publishes a message body to the specified topic
// where the message will queue at the channel level until the timeout expires, returning
// an error if publish failed
func (w *Producer) DeferredPublish(topic string, delay time.Duration, body []byte) error {
return w.sendCommand(DeferredPublish(topic, delay, body))
}

// DeferredPublishAsync publishes a message body to the specified topic
// where the message will queue at the channel level until the timeout expires
// but does not wait for the response from `nsqd`.
//
// When the Producer eventually receives the response from `nsqd`,
// the supplied `doneChan` (if specified)
// will receive a `ProducerTransaction` instance with the supplied variadic arguments
// and the response error if present
func (w *Producer) DeferredPublishAsync(topic string, delay time.Duration, body []byte,
doneChan chan *ProducerTransaction, args ...interface{}) error {
return w.sendCommandAsync(DeferredPublish(topic, delay, body), doneChan, args)
}

func (w *Producer) sendCommand(cmd *Command) error {
doneChan := make(chan *ProducerTransaction)
err := w.sendCommandAsync(cmd, doneChan, nil)
Expand Down

0 comments on commit b9b62d3

Please sign in to comment.