Exemple #1
0
func startNATS(host, user, pass string) *nats.Client {
	c := nats.NewClient()

	go func() {
		e := c.RunWithDefaults(host, user, pass)
		log.Fatalf("Failed to connect to nats server: %s", e.Error())
	}()

	return c
}
Exemple #2
0
func (r *Router) establishNATS() {
	r.natsClient = nats.NewClient()

	host := r.config.Nats.Host
	user := r.config.Nats.User
	pass := r.config.Nats.Pass

	go func() {
		for {
			e := r.natsClient.RunWithDefaults(host, user, pass)

			log.Warnf("Failed to connect to nats server: %s", e.Error())

			time.Sleep(1 * time.Second)

			r.natsClient = nats.NewClient()
		}
	}()
}