• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang sqs.SQS类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/sqs.SQS的典型用法代码示例。如果您正苦于以下问题:Golang SQS类的具体用法?Golang SQS怎么用?Golang SQS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SQS类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: deleteMessage

func deleteMessage(svc *sqs.SQS, queueURL string, receiptHandle string) error {
	params := &sqs.DeleteMessageInput{
		QueueUrl:      aws.String(queueURL),      // Required
		ReceiptHandle: aws.String(receiptHandle), // Required
	}
	_, err := svc.DeleteMessage(params)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:porcup,项目名称:ngproxy,代码行数:11,代码来源:sqs.go


示例17: createQueue

func createQueue(svc *sqs.SQS, queueName string) (string, error) {
	params := &sqs.CreateQueueInput{
		QueueName: aws.String(queueName), // Required
	}
	resp, err := svc.CreateQueue(params)

	if err != nil {
		return "", err
	}
	return *resp.QueueUrl, nil
}
开发者ID:porcup,项目名称:ngproxy,代码行数:11,代码来源:sqs.go


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


示例19: delete

func delete(qUrl string, svc *sqs.SQS, dx chan string) {
	for {
		m := <-dx

		params := &sqs.DeleteMessageInput{
			QueueUrl:      aws.String(qUrl), // Required
			ReceiptHandle: aws.String(m),    // Required
		}

		_, err := svc.DeleteMessage(params)

		if err != nil {
			log.Println("WARN - problem deleting messages from SQS, continuing.")
		}

	}
}
开发者ID:GeoNet,项目名称:haz,代码行数:17,代码来源:sqs.go


示例20: findQueueURL

func findQueueURL(sqsService *sqs.SQS, queueName string) string {
	// check the environment variable first
	var queueURL string
	if queueURL = os.Getenv("STREAMMARKER_SQS_QUEUE_URL"); queueURL != "" {
		return queueURL
	}

	// otherwise, query SQS for the queue URL
	params := &sqs.GetQueueUrlInput{
		QueueName: aws.String(queueName),
	}
	if resp, err := sqsService.GetQueueUrl(params); err == nil {
		queueURL = *resp.QueueUrl
	} else {
		stdlog.Panicf("Unable to retrieve queue URL: %s", err.Error())
	}
	return queueURL
}
开发者ID:skidder,项目名称:streammarker-collector,代码行数:18,代码来源:collector.go



注:本文中的github.com/aws/aws-sdk-go/service/sqs.SQS类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ssm.New函数代码示例发布时间:2022-05-24
下一篇:
Golang sqs.New函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap