1
0
Fork 0
shezmu/examples/daemons-kafka/daemons/price_consumer.go

27 lines
610 B
Go
Raw Normal View History

2015-10-15 23:35:03 +00:00
package daemons
import (
2015-10-24 16:28:17 +00:00
"time"
2015-10-15 23:35:03 +00:00
2016-07-26 22:05:34 +00:00
"github.com/localhots/shezmu/consumer"
2015-10-15 23:35:03 +00:00
)
// PriceConsumer consumes price update messages and prints them to the console.
type PriceConsumer struct {
2016-07-26 22:05:34 +00:00
consumer.Consumer
2015-10-15 23:35:03 +00:00
}
// PriceUpdate describes a price update message.
type PriceUpdate struct {
Product string `json:"product"`
Amount float64 `json:"amount"`
}
// Startup creates a new subscription for ProductPriceUpdates topic.
func (p *PriceConsumer) Startup() {
2015-10-24 16:28:17 +00:00
p.Subscribe("ProductPriceUpdates", func(u PriceUpdate) {
p.Logf("Price for %q is now $%.2f", u.Product, u.Amount)
2015-10-15 23:35:03 +00:00
})
2015-10-24 00:07:47 +00:00
p.LimitRate(5, time.Second)
2015-10-15 23:35:03 +00:00
}