summaryrefslogtreecommitdiff
path: root/nats/notify.go
diff options
context:
space:
mode:
Diffstat (limited to 'nats/notify.go')
-rw-r--r--nats/notify.go31
1 files changed, 31 insertions, 0 deletions
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
+}