Last active
September 27, 2021 17:06
-
-
Save Aneesh540/a068672aeab11d2b55b8eb24ad6fcdad to your computer and use it in GitHub Desktop.
Consumer-Naive-solution
This file contains hidden or 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 ( | |
nsq "github.com/nsqio/go-nsq" | |
) | |
func AddMongoDB(data){ | |
// your code for preprocessing and adding new value in mongoDB | |
} | |
var handleMessage = func(msg *nsq.Message) error { | |
var data interface{} | |
_ := json.Unmarshal(msg.Body, &data) | |
AddMongoDB(data) | |
return nil | |
} | |
func InitNsqConsumer(){ | |
nsqTopic := "dummy_topic" | |
nsqChannel := "dummy_channel" | |
consumer, err := nsq.NewConsumer(nsqTopic, nsqChannel, nsq.NewConfig()) | |
consumer.AddHandler(nsq.HandleFunc(handleMessage)) | |
err = consumer.ConnectToNSQLookupd("127.0.0.1:4161") | |
if err != nil{ | |
log.Print("error connecting to nsqlookupd") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment