2021-06-06 03:46:11 +03:00
|
|
|
package events
|
2021-06-03 09:30:25 +03:00
|
|
|
|
|
|
|
import (
|
2021-06-06 03:46:11 +03:00
|
|
|
"git/ecom/jira-bot/pkg/config"
|
2021-06-03 09:30:25 +03:00
|
|
|
"log"
|
|
|
|
|
2021-06-06 03:46:11 +03:00
|
|
|
"github.com/davecgh/go-spew/spew"
|
2021-06-03 09:30:25 +03:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2021-06-06 03:46:11 +03:00
|
|
|
func Listen(cfg *config.Config) {
|
2021-06-03 09:30:25 +03:00
|
|
|
cf := nsq.NewConfig()
|
2021-06-06 03:46:11 +03:00
|
|
|
|
|
|
|
cf.ClientID = "jirabot"
|
|
|
|
cf.Hostname = "ekb-web02.myway.local"
|
|
|
|
cf.LookupdPollInterval = cf.LookupdPollInterval / 2
|
|
|
|
spew.Dump(cf)
|
2021-06-03 09:30:25 +03:00
|
|
|
|
2021-06-06 03:46:11 +03:00
|
|
|
consumer, err := nsq.NewConsumer("telegram", "jira", cf)
|
2021-06-03 09:30:25 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-06-06 03:46:11 +03:00
|
|
|
|
|
|
|
consumer.SetLoggerLevel(nsq.LogLevelError)
|
2021-06-03 09:30:25 +03:00
|
|
|
consumer.AddHandler(&myMessageHandler{})
|
|
|
|
|
2021-06-06 03:46:11 +03:00
|
|
|
err = consumer.ConnectToNSQLookupd("ekb-web02.myway.local:4161")
|
2021-06-03 09:30:25 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|