You've already forked gobuch-trainingfellow
mirror of
https://github.com/SourceFellows/trainingfellow.git
synced 2025-08-06 06:12:16 +02:00
initial import
This commit is contained in:
34
registrierung/nats/notifier.go
Normal file
34
registrierung/nats/notifier.go
Normal file
@ -0,0 +1,34 @@
|
||||
package nats
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
"training-fellow.de/registrierung"
|
||||
)
|
||||
|
||||
func NewNotifier(url string) *notifier {
|
||||
return ¬ifier{url}
|
||||
}
|
||||
|
||||
type notifier struct {
|
||||
url string
|
||||
}
|
||||
|
||||
func (nn *notifier) InformAboutNewRegistrierung(registrierung *registrierung.Registrierung) error {
|
||||
|
||||
notifierLogger := log.WithField("Registrierung", registrierung)
|
||||
notifierLogger.Info("Inform about new Registrierung")
|
||||
|
||||
nc, err := nats.Connect(nn.url)
|
||||
if err != nil {
|
||||
notifierLogger.Error("Could not connect to server: ", err)
|
||||
return err
|
||||
}
|
||||
defer nc.Close()
|
||||
c, _ := nats.NewEncodedConn(nc, nats.JSON_ENCODER)
|
||||
defer c.Close()
|
||||
|
||||
return c.Publish("traingfellow.registrierung.neu", registrierung)
|
||||
|
||||
}
|
Reference in New Issue
Block a user