diff options
Diffstat (limited to 'nats')
-rw-r--r-- | nats/constants.go | 5 | ||||
-rw-r--r-- | nats/notify.go | 31 |
2 files changed, 36 insertions, 0 deletions
diff --git a/nats/constants.go b/nats/constants.go new file mode 100644 index 0000000..82436b5 --- /dev/null +++ b/nats/constants.go @@ -0,0 +1,5 @@ +package nats + +const ( + NATS_TOPIC_REGISTRATION_NEW = "uvok.de.go.training_fellow.registration.new" +) diff --git a/nats/notify.go b/nats/notify.go new file mode 100644 index 0000000..56cbc7f --- /dev/null +++ b/nats/notify.go @@ -0,0 +1,31 @@ +package nats + +import ( + "github.com/nats-io/nats.go" + "uvok.de/go/training_fellow/registration" +) + +type NatsNotifier struct { +} + +func (notif *NatsNotifier) NotifyNewRegistration(reg *registration.Registration) error { + conn, err := nats.Connect("nats://nats-server:4222") + if err != nil { + return err + } + defer conn.Close() + + enc_conn, err := nats.NewEncodedConn(conn, nats.JSON_ENCODER) + + if err != nil { + return err + } + + defer enc_conn.Close() + + err = enc_conn.Publish(NATS_TOPIC_REGISTRATION_NEW, reg) + if err != nil { + return err + } + return nil +} |