Example #1
0
func (l *SQSListener) handle(msg *sqs.Message, q *sqs.Queue) {
	err := l.Handler.Handle(msg)
	if err != nil {
		q.ChangeMessageVisibility(msg, 10)
		fmt.Println(err)
		return
	}
	_, err = q.DeleteMessage(msg)
	if err != nil {
		fmt.Println("unable to delete msg: ", err)
	}
}
Example #2
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 handleMessage(q *sqs.Queue, m *sqs.Message, h Handler, client twilio.Client, sender string) error {
	var err error
	err = h.HandleMessage(m)
	fmt.Println("Sending the following message : ", m.Body)
	receiver := m.MessageAttribute[1].Value.StringValue // collect the mobile number
	fmt.Println("To : ", receiver)
	fmt.Println("\n")
	message, err2 := twilio.NewMessage(client, sender, receiver, twilio.Body(m.Body))

	// verification
	if err2 != nil {
		fmt.Println(err2)
	} else {
		fmt.Println(message.Status)
	}
	if err != nil {
		return err
	}
	// delete
	_, err = q.DeleteMessage(m)
	return err
}