first commit
way too late.
This commit is contained in:
commit
d4f7dc57fc
53 files changed
+3518
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package nsqpublisher
|
||||
|
||||
import (
|
||||
"github.com/bitly/go-nsq"
|
||||
"github.com/didiercrunch/doormanserver/shared"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
type NsqPublisher struct {
|
||||
Config *nsq.Config
|
||||
Producer *nsq.Producer
|
||||
}
|
||||
|
||||
func (pub *NsqPublisher) InitConfig() {
|
||||
pub.Config = nsq.NewConfig()
|
||||
}
|
||||
|
||||
func (pub *NsqPublisher) Init() error {
|
||||
var err error
|
||||
pub.InitConfig()
|
||||
pub.Producer, err = nsq.NewProducer(shared.GetParams().NSQ.NSQLookupdUrl, pub.Config)
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
func (pub *NsqPublisher) Stop() error {
|
||||
pub.Producer.Stop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pub *NsqPublisher) Emit(doormanId bson.ObjectId, doorman shared.AsDoormanUpdatePayloader) error {
|
||||
topic := doormanId.Hex()
|
||||
if data, err := doorman.AsDoormanUpdatePayload(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return pub.Producer.Publish(topic, data)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user