Exemplo n.º 1
0
/*
*	Handlers
 */
func handleProductCreated(msg []byte) {
	fmt.Println("[INFO] Received Kafka message from topic 'product_created'")
	p := models.Product{}
	if err := json.Unmarshal(msg, &p); err != nil {
		fmt.Println("[ERROR] Unable to Unmarshal json from message 'product_created'", err.Error())
		return
	}
	p.CurrQuantity = 100000
	p.MinQuantity = 90

	rand.Seed(time.Now().UTC().UnixNano())
	p.CurrentValue = float64(rand.Intn(10)) / 10.0

	if err := p.Save(db); err != nil {
		producer.Publish("product_created_dead_letter", msg)
	}
}