Пример #1
0
// Performed only once the first time a producer is needed. Sets up a slice of
// nsq.Producer which will be used round-robin.
func setupProducers() {
	// Create an empty pool of producers
	ppool = make([]*nsq.Producer, 0)

	// Determine how many producers with the NSQD_POOL environment variable.
	// Defaults to 1
	pcount = 1
	if env.Get("NSQD_POOL") != "" {
		num, err := strconv.Atoi(env.Get("NSQD_POOL"))
		if err == nil && num > 0 {
			pcount = num
		}
	}

	// Get the nsqd host (you can use haproxy if > 1 pool connection)
	host := env.GetOr("NSQD_HOST", "127.0.0.1:4150")

	// Fill the pool with connections
	for i := 0; i < pcount; i++ {
		p, err := nsq.NewProducer(host, nsq.NewConfig())
		if err != nil {
			panic(err)
		}
		ppool = append(ppool, p)
	}
}
Пример #2
0
func getConcurrency(key string, fallback int) int {
	if s := env.Get("TOPIC_CONCURRENCY_" + strings.ToUpper(key)); s != "" {
		if n, err := strconv.Atoi(s); err == nil && n > 0 {
			return n
		}
	}

	return fallback
}