// Author: Guillermo Céspedes // I recommend using the "to_nsq" command instead of the producer.go // $ cat inputUsers_6.txt | to_nsq -topic="topic_test" -nsqd-tcp-address="127.0.0.1:4150" // I leave the code as an example, in case you want to use it in another way. package main import ( "log" "strconv" "github.com/nsqio/go-nsq" ) func main() { // Quick and basic configuration config := nsq.NewConfig() // Create a NewProducer w, _ := nsq.NewProducer("127.0.0.1:4150", config) // TODO: The speed at which messages are prepared to be sent to the queue must be optimized. var buf [][]byte for i := 0; i < 531441; i++ { buf = append(buf, []byte(strconv.Itoa(i))) // err := w.Publish("topic_test", []byte(strconv.Itoa(i))) // if err != nil { // log.Panic("Could not connect") // } } // TODO: https://nsq.io/components/nsqd.html#post-mpub // Send multiple messages to the queue. err := w.MultiPublish("topic_test", buf); if err != nil { log.Panic("error connect") } w.Stop() }