本文整理汇总了Golang中github.com/crowdmob/goamz/sqs.Queue类的典型用法代码示例。如果您正苦于以下问题:Golang Queue类的具体用法?Golang Queue怎么用?Golang Queue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Queue类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: waitForMessages
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)
}
示例2: handle
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)
}
}
示例3: deleteFromQueueOnce
func deleteFromQueueOnce(q *sqs.Queue, del chan string, timeout time.Duration) error {
batch := assembleDeleteMessageBatch(del, timeout)
if len(batch) > 0 {
log.Printf("deleting %d messages from q\n", len(batch))
_, err := q.DeleteMessageBatch(batch)
if err != nil {
return err
}
}
return nil
}
示例4: readFromQueueOnce
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
}
示例5: pushMessage
func pushMessage(q *sqs.Queue, message interface{}) error {
j, err := json.Marshal(message)
if err != nil {
return err
}
_, err = q.SendMessage(string(j))
if err != nil {
return err
}
return nil
}
示例6: listenOnQueue
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)
}
}
}
示例7: writeToQueueOnce
func (w *SQSWriter) writeToQueueOnce(q *sqs.Queue) error {
batch, err := w.assembleSendMessageBatch()
if err != nil {
return err
}
if len(batch) > 0 {
w.Logger.Printf("%s: sending %d messages to q\n", w.QueueName, len(batch))
result, err := q.SendMessageBatch(batch)
if err != nil {
w.Logger.Printf("%#v\n", result)
return err
}
}
return nil
}
示例8: Start
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)
}
}
示例9: handle
func (s *SQSClient) handle(message string, q *sqs.Queue) error {
var res *sqs.SendMessageResponse
err := Retrier.Retry(func() error {
// Call sqs.Queue.SendMessage() - initiates a HTTP request.
var e error
res, e = q.SendMessage(message)
return e
})
if err != nil {
return err
}
// check md5
expectedHash := md5.New()
expectedHash.Write([]byte(message))
expected := fmt.Sprintf("%x", expectedHash.Sum(nil))
if expected != res.MD5 {
return errors.New(fmt.Sprintf("message %s Did Not match expected %s", res.MD5, expected))
}
return nil
}
示例10: handleMessage
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
}