-
-
Save larzconwell/767daa616e4718dc2d4bc0b3e4495599 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"sync" | |
nsq "github.com/bitly/go-nsq" | |
) | |
const ( | |
addr = "127.0.0.1:4150" | |
topic = "ex_topic" | |
batches = 10000 | |
) | |
var ( | |
message = []byte("example") | |
messages = [][]byte{ | |
message, message, | |
message, message, | |
message, message, | |
message, message, | |
message, message, | |
} | |
) | |
type Logger struct{} | |
func (Logger) Output(c int, s string) error { | |
log.Println(s) | |
return nil | |
} | |
func main() { | |
config := nsq.NewConfig() | |
producer, err := nsq.NewProducer(addr, config) | |
if err != nil { | |
log.Println(err) | |
return | |
} | |
producer.SetLogger(new(Logger), nsq.LogLevelInfo) | |
defer producer.Stop() | |
var wg sync.WaitGroup | |
defer wg.Wait() | |
wg.Add(batches) | |
for i := 0; i < batches; i++ { | |
go func() { | |
defer wg.Done() | |
err = producer.MultiPublish(topic, messages) | |
if err != nil { | |
log.Println(err) | |
} | |
}() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment