Beispiel #1
0
func init() {

	stanOpts := streaming.StanOptions{}
	stanOpts.Options = nats.DefaultOptions

	parse.Populate(&stanOpts, config.Conf, "stan")
	parse.Populate(&stanOpts.Options, config.Conf, "stan.nats")

	// make client id unique
	stanOpts.ClientId = stanOpts.ClientId + "-" + helpers.RandStringBytesMaskImprSrc(5)

	Info.Printf("Stan underlying Nats options: %#v", stanOpts.Options)

	stanOpts.AsyncErrorCB = func(c *nats.Conn, s *nats.Subscription, err error) {
		Error.Println("Got stan nats async error:", err)
	}

	stanOpts.DisconnectedCB = func(c *nats.Conn) {
		Warning.Println("Stan Nats disconnected")
	}

	stanOpts.ReconnectedCB = func(c *nats.Conn) {
		Info.Println("Stan Nats reconnected")
	}

	Info.Print("Connecting to stan nats")
	var (
		err error
	)
	attempts := 1
	for attempts <= 5 {
		attempts++
		StanConn, err = stanOpts.Connect()
		if err == nil {
			break
		} else {
			Warning.Println(err)
		}
		time.Sleep(2 * time.Second)
	}

	if err != nil {
		panic("Failed to get stan con:" + err.Error())
	}
	Info.Println("Connected to nats streaming server")
}
Beispiel #2
0
func init() {

	mConf := &mongo.MongoConf{}
	parse.Populate(mConf, config.Conf, "mongo")
	Info.Println("Mongo config:", mConf)

	Info.Println("Attempting to connect to [" + mConf.Url + "]")

	session = mongo.InitFromConfig(mConf, Trace)
}
Beispiel #3
0
func init() {

	natsOpts := natsio.NewNatsOptions(func(n *natsio.NatsOptions) error { return nil })

	natsOpts.Options.MaxReconnect = 15

	parse.Populate(&natsOpts.Options, config.Conf, "nats")

	Info.Printf("Nats options: %#v", natsOpts)

	encoding := config.Conf.GetDefaultString("nats.encoding", natsOpts.GetEncoding())

	Info.Println("Nats encoding:", encoding)
	natsOpts.SetEncoding(encoding)

	natsOpts.Options.AsyncErrorCB = func(c *nats.Conn, s *nats.Subscription, err error) {
		Error.Println("Got nats async error:", err)
	}

	natsOpts.Options.DisconnectedCB = func(c *nats.Conn) {
		Warning.Println("Nats disconnected")
	}

	natsOpts.Options.ReconnectedCB = func(c *nats.Conn) {
		Info.Println("Nats reconnected")
	}

	var err error

	Info.Print("Connecting to nats")
	attempts := 1
	for attempts <= 5 {
		attempts++
		Conn, err = natsOpts.Connect()
		if err == nil {
			break
		} else {
			Warning.Println(err)
		}
		time.Sleep(2 * time.Second)
	}

	if err != nil {
		panic("Failed to connect to nats:" + err.Error())
	}
	Info.Print("Connected to nats")
}
Beispiel #4
0
func init() {

	migrationsPath := ""
	mysql.Init(func(c *mysql.Config) {
		parse.Populate(c, config.Conf, "mysql")

		migrationsPath = c.MigrationsPath
		c2, err := mysqlReal.ParseDSN(c.ConnectString)
		if err == nil {
			Info.Printf("Attempting to connect to %s@%s\n", c2.User, c2.Addr)
		} else {
			Error.Println("Error parsing DSN:", c.ConnectString)
		}
	})

	if migrationsPath != "" {
		mysql.Migrate(migrationsPath)
	}
}