summaryrefslogtreecommitdiff
path: root/nats
diff options
context:
space:
mode:
authoruvok cheetah2023-12-08 17:05:40 +0000
committeruvok cheetah2023-12-08 17:05:40 +0000
commite6d7e091b7b6dde1c736e7baf01fad5fd5c1ce27 (patch)
tree38a11d4df6a3661ba9eec8d0e7c7df0d9116a19d /nats
Initial Commit
Diffstat (limited to 'nats')
-rw-r--r--nats/constants.go5
-rw-r--r--nats/notify.go31
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
+}