Esempio n. 1
0
func (l *SQSListener) waitForMessages(q *sqs.Queue) {
	msgResponse, err := q.ReceiveMessage(1)
	if err != nil || len(msgResponse.Messages) < 1 {
		time.Sleep(l.PollInterval)
		return
	}
	l.handle(&msgResponse.Messages[0], q)
}
Esempio n. 2
0
func (r *SQSReader) readFromQueueOnce(q *sqs.Queue) error {
	r.Logger.Printf("%s: reading messages from queue\n", r.QueueName)
	results, err := q.ReceiveMessage(RECV_MAX_MESSAGES)
	if err != nil {
		return err
	}

	r.Logger.Printf("%s: read %d messages\n", r.QueueName, len(results.Messages))
	for _, message := range results.Messages {
		r.enqueueMessage(message.Body, message.ReceiptHandle)
	}

	return nil
}
Esempio n. 3
0
func listenOnQueue(q *sqs.Queue, ch chan *sqs.Message) {

	for {
		resp, err := q.ReceiveMessage(1)
		if err != nil {
			log.Panic(err)
		}

		for _, m := range resp.Messages {
			ch <- &m
			q.DeleteMessage(&m)
		}
	}

}
func Start(q *sqs.Queue, h Handler, t time.Duration, receiveMessageNum int, client twilio.Client, sender string) {
	fmt.Println(fmt.Sprintf("worker: Start polling  [%s]", time.Now().Local()))
	for {
		resp, err := q.ReceiveMessage(receiveMessageNum)
		if err != nil {
			log.Println(err)
			continue
		}
		if len(resp.Messages) > 0 {
			fmt.Printf("\r")
			run(q, h, resp, client, sender)
		} else {
			fmt.Printf(".")
		}
		time.Sleep(t)
	}
}