diff options
author | uvok cheetah | 2023-12-08 17:05:40 +0000 |
---|---|---|
committer | uvok cheetah | 2023-12-08 17:05:40 +0000 |
commit | e6d7e091b7b6dde1c736e7baf01fad5fd5c1ce27 (patch) | |
tree | 38a11d4df6a3661ba9eec8d0e7c7df0d9116a19d /nats/notify.go |
Initial Commit
Diffstat (limited to 'nats/notify.go')
-rw-r--r-- | nats/notify.go | 31 |
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 +} |