Ejemplo n.º 1
0
// Interface from rmq
func (r *RedisQueue) Consume(delivery rmq.Delivery) {
	fmt.Println("Got event from queue:", delivery.Payload())

	event := entities.Event{}

	if err := json.Unmarshal([]byte(delivery.Payload()), &event); err != nil {
		fmt.Println("Error consuming event, unable to deserialise event")
		// handle error
		delivery.Reject()
		return
	}
	delivery.Ack()

	r.callback(&event)
}
Ejemplo n.º 2
0
func (consumer *Consumer) Consume(delivery rmq.Delivery) {
	consumer.count++
	if consumer.count%batchSize == 0 {
		duration := time.Now().Sub(consumer.before)
		consumer.before = time.Now()
		perSecond := time.Second / (duration / batchSize)
		log.Printf("%s consumed %d %s %d", consumer.name, consumer.count, delivery.Payload(), perSecond)
	}
	time.Sleep(time.Millisecond)
	if consumer.count%batchSize == 0 {
		delivery.Reject()
	} else {
		delivery.Ack()
	}
}