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


Golang sqs.SQS類代碼示例

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


在下文中一共展示了SQS類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: createQueue

func createQueue(svc *sqs.SQS, queueName string) {
	params := &sqs.CreateQueueInput{
		QueueName: &queueName,
	}
	_, err := svc.CreateQueue(params)
	if err != nil {
		log.Fatal(err)
	}
}
開發者ID:DreamItGetIT,項目名稱:sqs-initialiser,代碼行數:9,代碼來源:create_queues.go

示例3: checkQueueSize

func checkQueueSize(s *sqs.SQS, queueURL *string, avail, inFlight, delayed int64) {
	// Get All Attributes.
	respAttr, err := s.GetQueueAttributes(&sqs.GetQueueAttributesInput{
		QueueUrl:       queueURL,
		AttributeNames: []*string{aws.String(gqa.AttrAll)},
	})

	So(err, ShouldBeNil)
	So(*respAttr.Attributes[gqa.AttrApproximateNumberOfMessages], ShouldEqual, strconv.FormatInt(avail, 10))
	So(*respAttr.Attributes[gqa.AttrApproximateNumberOfMessagesNotVisible], ShouldEqual, strconv.FormatInt(inFlight, 10))
	So(*respAttr.Attributes[gqa.AttrApproximateNumberOfMessagesDelayed], ShouldEqual, strconv.FormatInt(delayed, 10))
}
開發者ID:vburenin,項目名稱:firempq,代碼行數:12,代碼來源:sqsproto_test.go

示例4: deleteMessage

func deleteMessage(svc *sqs.SQS, msgs ...*sqs.Message) error {
	// delete messages
	delParams := sqs.DeleteMessageInput{
		QueueUrl: queueURL,
	}

	for i, msg := range msgs {
		delParams.ReceiptHandle = msg.ReceiptHandle
		_, err := svc.DeleteMessage(&delParams)
		if err != nil {
			return err
		}

		fmt.Printf("message deleted %v: %v\n", i, *msg.Body)
	}

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

示例5: sendMessage

// sendMessage sends msgs to SQS.
func sendMessage(svc *sqs.SQS, msgs ...string) error {
	// create message send params
	sendParams := sqs.SendMessageInput{
		QueueUrl: queueURL,
	}

	// send message
	for i, msg := range msgs {
		// message body is a datetime string
		sendParams.MessageBody = aws.String(msg)
		_, err := svc.SendMessage(&sendParams)
		if err != nil {
			return err
		}

		fmt.Printf("message sent %v: %v\n", i, msg)
	}

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

示例6: SendMessageBatch

func SendMessageBatch(s *sqs.SQS, req *sqs.SendMessageBatchInput, id2index map[string]int) error {
	resp, err := s.SendMessageBatch(req)
	if err != nil {
		return err
	}
	return queue.NewBatchError(id2index, resp.Failed)
}
開發者ID:nabeken,項目名稱:delayd2,代碼行數:7,代碼來源:relay.go

示例7: 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

示例8: 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

示例9: sendMessage

func sendMessage(sqsInstance *sqs.SQS, queueURL *string, message string) error {
	_, err := sqsInstance.SendMessage(&sqs.SendMessageInput{
		QueueURL:    queueURL,
		MessageBody: &message,
	})
	return err
}
開發者ID:matematik7,項目名稱:sqs-test,代碼行數:7,代碼來源:main.go

示例10: Main

func Main() {
	var (
		SQS                        *sqs.SQS
		getUserQueueUrlOutput      *sqs.GetQueueUrlOutput
		getContainerQueueUrlOutput *sqs.GetQueueUrlOutput
		UserQueueUrl               *string
		ContainerQueueUrl          *string

		Dynamo *dynamodb.DynamoDB

		socialWorker *workers.SocialWorker
	)

	SQS = sqs.New(&aws.Config{Region: aws.String("cn-north-1")})
	getUserQueueUrlOutput, err := SQS.GetQueueUrl(&sqs.GetQueueUrlInput{QueueName: aws.String(USER_QUEUE_NAME)})
	if err != nil {
		glog.Errorln("Error on connect user queue url:", err.Error())
		return
	}
	UserQueueUrl = getUserQueueUrlOutput.QueueUrl
	getContainerQueueUrlOutput, err = SQS.GetQueueUrl(&sqs.GetQueueUrlInput{QueueName: aws.String(CONTAINER_QUEUE_NAME)})
	if err != nil {
		glog.Errorln("Error on connect container queue url:", err.Error())
		return
	}
	ContainerQueueUrl = getContainerQueueUrlOutput.QueueUrl

	Dynamo = dynamodb.New(&aws.Config{Region: aws.String("cn-north-1")})

	socialWorker = workers.NewSocialWorker(SQS, UserQueueUrl, ContainerQueueUrl, Dynamo)
	socialWorker.Start()
}
開發者ID:luzh0422,項目名稱:spider-docker,代碼行數:32,代碼來源:hypervisor.go

示例11: get_queue

func get_queue(svc *sqs.SQS, queue string) (*string, error) {
    params := &sqs.GetQueueUrlInput{
        QueueName: aws.String(queue),
    }
    resp, err := svc.GetQueueUrl(params)
    if err != nil { return nil, err }
    return resp.QueueUrl, nil
}
開發者ID:relud,項目名稱:heka_plugin_sqs3,代碼行數:8,代碼來源:sqs3_input.go

示例12: deleteQueue

func deleteQueue(s *sqs.SQS, queueName string) {
	resp, err := s.GetQueueUrl(&sqs.GetQueueUrlInput{QueueName: aws.String(queueName)})
	if err != nil {
		So(err.Error(), ShouldContainSubstring, "AWS.SimpleQueueService.NonExistentQueue")
	} else {
		_, e := s.DeleteQueue(&sqs.DeleteQueueInput{QueueUrl: resp.QueueUrl})
		So(e, ShouldBeNil)
	}
}
開發者ID:vburenin,項目名稱:firempq,代碼行數:9,代碼來源:sqsproto_test.go

示例13: delete_message

func delete_message(svc *sqs.SQS, queue_url *string, receipt_handle *string) error {
    params := &sqs.DeleteMessageInput{
        QueueUrl: queue_url,
        ReceiptHandle: receipt_handle,
    }
    _, err := svc.DeleteMessage(params)
    if err != nil { return err }
    return nil
}
開發者ID:relud,項目名稱:heka_plugin_sqs3,代碼行數:9,代碼來源:sqs3_input.go

示例14: createQueue

func createQueue(sqsInstance *sqs.SQS, queueName string) (*string, error) {
	createQueueOutput, err := sqsInstance.CreateQueue(&sqs.CreateQueueInput{QueueName: &queueName})

	if err != nil {
		return nil, err
	}

	return createQueueOutput.QueueURL, nil
}
開發者ID:matematik7,項目名稱:sqs-test,代碼行數:9,代碼來源:main.go

示例15: getQueue

func getQueue(sqsInstance *sqs.SQS, queueName string) (*string, error) {
	queueURLOutput, err := sqsInstance.GetQueueURL(&sqs.GetQueueURLInput{QueueName: &queueName})

	if err != nil {
		return nil, err
	}

	return queueURLOutput.QueueURL, nil
}
開發者ID:matematik7,項目名稱:sqs-test,代碼行數:9,代碼來源:main.go


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