blob: 56cbc7ff0b65d86e4f5584b692bc96d2d3b59118 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
}
|