當前位置: 首頁>>代碼示例>>Golang>>正文


Golang SQS.ReceiveMessage方法代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/sqs.SQS.ReceiveMessage方法的典型用法代碼示例。如果您正苦於以下問題:Golang SQS.ReceiveMessage方法的具體用法?Golang SQS.ReceiveMessage怎麽用?Golang SQS.ReceiveMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/aws/aws-sdk-go/service/sqs.SQS的用法示例。


在下文中一共展示了SQS.ReceiveMessage方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getMessage

// Get Message Function
// Takes SQS Object, Queue_url, and Message Attributes
// Returns a ReceiveMessageOutput Struct and Errors
func getMessage(queue *sqs.SQS, queue_url *string, message_attributes []*string) (sqs.Message, error) {

	// Params object of ReceiveMessageInput Struct
	params := &sqs.ReceiveMessageInput{
		QueueURL:              queue_url,
		MessageAttributeNames: message_attributes,
		MaxNumberOfMessages:   aws.Long(1),
		VisibilityTimeout:     aws.Long(1),
		WaitTimeSeconds:       aws.Long(1),
	}
	resp, err := queue.ReceiveMessage(params)

	message := *resp.Messages[0]
	return message, err
}
開發者ID:grubernaut,項目名稱:GoSlurp,代碼行數:18,代碼來源:goslurp.go

示例2: receive_from_queue

func receive_from_queue(svc *sqs.SQS, queue_url *string) (*string, *string, *string, error) {
    // get sqs message
    params := &sqs.ReceiveMessageInput{
        QueueUrl: queue_url,
        MaxNumberOfMessages: aws.Int64(1),
        VisibilityTimeout: aws.Int64(1),
    }
    resp, err := svc.ReceiveMessage(params)
    if err != nil { return nil, nil, nil, err }

    // error on empty queue
    if len(resp.Messages) == 0 { return nil, nil, nil, errors.New("queue is empty") }

    receipt_handle := resp.Messages[0].ReceiptHandle
    body := resp.Messages[0].Body

    // unmarshal sqs message body
    data := &SqsBody{}
    err = json.Unmarshal([]byte(*body), &data)
    if err != nil { return nil, nil, nil, err }

    bucket := &data.Records[0].S3.Bucket.Name
    key := &data.Records[0].S3.Object.Key
    return receipt_handle, bucket, key, nil
}
開發者ID:relud,項目名稱:heka_plugin_sqs3,代碼行數:25,代碼來源:sqs3_input.go

示例3: receive

func receive(qUrl string, svc *sqs.SQS, rx chan msg.Raw) {
	for {
		param := &sqs.ReceiveMessageInput{
			QueueUrl:            aws.String(qUrl),
			MaxNumberOfMessages: aws.Int64(int64(MaxNumberOfMessages)),
			VisibilityTimeout:   aws.Int64(int64(VisibilityTimeout)),
			WaitTimeSeconds:     aws.Int64(int64(WaitTimeSeconds)),
		}

		r, err := svc.ReceiveMessage(param)
		if err != nil {
			log.Println("WARN - problem receiving messages from SQS, sleeping, continuing.")
			time.Sleep(retry)
			continue
		}

		if (len(r.Messages)) > 0 {
			for _, raw := range r.Messages {
				m := msg.Raw{
					Body:          *raw.Body,
					ReceiptHandle: *raw.ReceiptHandle,
				}
				rx <- m
			}
		}
	}
}
開發者ID:GeoNet,項目名稱:haz,代碼行數:27,代碼來源:sqs.go

示例4: run

func run(svc *sqs.SQS, params *sqs.ReceiveMessageInput) {
	for {
		resp, err := svc.ReceiveMessage(params)
		if err != nil {
			fmt.Println("There was an issue receiving a message: ", err)
		}

		renderIntoTemplate()

		if len(resp.Messages) > 0 {
			fmt.Printf("\nDisplay received message:\n\n%+v", resp)
		}

		time.Sleep(5 * time.Second) // message needs to be explicitly deleted still
	}
}
開發者ID:Integralist,項目名稱:gophant-renderer,代碼行數:16,代碼來源:renderer.go

示例5: receiveMessage

func receiveMessage(svc *sqs.SQS, queueURL string) (*sqs.Message, error) {

	params := &sqs.ReceiveMessageInput{
		QueueUrl:            aws.String(queueURL), // Required
		MaxNumberOfMessages: aws.Int64(1),
		VisibilityTimeout:   aws.Int64(1),
		WaitTimeSeconds:     aws.Int64(1),
	}
	resp, err := svc.ReceiveMessage(params)

	if err != nil {
		return nil, err
	}

	for _, item := range resp.Messages {
		return item, nil
	}
	return nil, nil
}
開發者ID:porcup,項目名稱:ngproxy,代碼行數:19,代碼來源:sqs.go

示例6: receiveMessage

// receiveMessage receives messages up to count.
func receiveMessage(svc *sqs.SQS, count int64) ([]*sqs.Message, error) {
	// create message receiption params
	rcvParams := sqs.ReceiveMessageInput{
		QueueUrl:            queueURL,
		MaxNumberOfMessages: aws.Int64(count),
	}

	// receive message
	res, err := svc.ReceiveMessage(&rcvParams)
	if err != nil {
		return nil, err
	}

	for i, msg := range res.Messages {
		fmt.Printf("message received %v: %v\n", i, *msg.Body)
	}

	return res.Messages, nil
}
開發者ID:skatsuta,項目名稱:aws-sdk-go-sample,代碼行數:20,代碼來源:main.go

示例7: getMessages

func getMessages(x int, sqssvc *sqs.SQS, wg *sync.WaitGroup) {
	defer wg.Done()

	params := &sqs.ReceiveMessageInput{
		QueueUrl:            aws.String("https://sqs.us-west-2.amazonaws.com/123456789098/sqs-queue-name"),
		MaxNumberOfMessages: aws.Int64(10),
		VisibilityTimeout:   aws.Int64(30),
		WaitTimeSeconds:     aws.Int64(0),
	}

	resp, err := sqssvc.ReceiveMessage(params)
	if err != nil {
		log.Printf("error reading from sqs: %v\n", err)
		os.Exit(1)
	}

	log.Printf("routine: %d count: %v\n", x, len(resp.Messages))
	for _, message := range resp.Messages {
		log.Printf("routine: %d body %s\n", x, *message.Body)
	}
}
開發者ID:gombadi,項目名稱:go-samples,代碼行數:21,代碼來源:aws-sqs-goroutines.go


注:本文中的github.com/aws/aws-sdk-go/service/sqs.SQS.ReceiveMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。