From e6d7e091b7b6dde1c736e7baf01fad5fd5c1ce27 Mon Sep 17 00:00:00 2001 From: uvok cheetah Date: Fri, 8 Dec 2023 17:05:40 +0000 Subject: Initial Commit --- nats/notify.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 nats/notify.go (limited to 'nats/notify.go') 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 +} -- cgit v1.2.3