jira-bot/pkg/events/message.go
Andrey Belvedersky f3175b8ce9 add config
2021-06-06 03:46:11 +03:00

48 lines
921 B
Go

package events
import (
"git/ecom/jira-bot/pkg/config"
"log"
"github.com/davecgh/go-spew/spew"
"github.com/nsqio/go-nsq"
)
type myMessageHandler struct{}
func processMessage(b []byte) error {
log.Println(string(b))
return nil
}
// HandleMessage implements the Handler interface.
func (h *myMessageHandler) HandleMessage(m *nsq.Message) error {
if len(m.Body) == 0 {
return nil
}
err := processMessage(m.Body)
return err
}
func Listen(cfg *config.Config) {
cf := nsq.NewConfig()
cf.ClientID = "jirabot"
cf.Hostname = "ekb-web02.myway.local"
cf.LookupdPollInterval = cf.LookupdPollInterval / 2
spew.Dump(cf)
consumer, err := nsq.NewConsumer("telegram", "jira", cf)
if err != nil {
log.Fatal(err)
}
consumer.SetLoggerLevel(nsq.LogLevelError)
consumer.AddHandler(&myMessageHandler{})
err = consumer.ConnectToNSQLookupd("ekb-web02.myway.local:4161")
if err != nil {
log.Fatal(err)
}
}