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

Golang sqs.New函数代码示例

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

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



在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: recieve

// Check to see if we have a message on the queue
func (s *Sqs) recieve() int {

	if s.svc == nil {
		s.svc = sqs.New(&aws.Config{Region: s.Region})
	}

	params := &sqs.ReceiveMessageInput{
		QueueURL:            aws.String(s.Url),
		MaxNumberOfMessages: aws.Long(10),
	}
	resp, err := s.svc.ReceiveMessage(params)

	if err != nil {
		// A non-service error occurred.
		s.Log.Error(err.Error())
		return 0
	}

	numMsg := len(resp.Messages)
	if numMsg == 0 {
		return 0
	}

	for _, element := range resp.Messages {
		s.processRaw(*element.Body)
		s.remove(element)
	}

	return numMsg
}
开发者ID:hyprstack,项目名称:eevy,代码行数:31,代码来源:sqs.go


示例2: ExampleSQS_ChangeMessageVisibilityBatch

func ExampleSQS_ChangeMessageVisibilityBatch() {
	svc := sqs.New(nil)

	params := &sqs.ChangeMessageVisibilityBatchInput{
		Entries: []*sqs.ChangeMessageVisibilityBatchRequestEntry{ // Required
			&sqs.ChangeMessageVisibilityBatchRequestEntry{ // Required
				ID:                aws.String("String"), // Required
				ReceiptHandle:     aws.String("String"), // Required
				VisibilityTimeout: aws.Long(1),
			},
			// More values...
		},
		QueueURL: aws.String("String"), // Required
	}
	resp, err := svc.ChangeMessageVisibilityBatch(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
开发者ID:navneet-flipkart,项目名称:confd,代码行数:34,代码来源:examples_test.go


示例3: ExampleSQS_SetQueueAttributes

func ExampleSQS_SetQueueAttributes() {
	svc := sqs.New(nil)

	params := &sqs.SetQueueAttributesInput{
		Attributes: &map[string]*string{ // Required
			"Key": aws.String("String"), // Required
			// More values...
		},
		QueueURL: aws.String("String"), // Required
	}
	resp, err := svc.SetQueueAttributes(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
开发者ID:navneet-flipkart,项目名称:confd,代码行数:30,代码来源:examples_test.go


示例4: ExampleSQS_GetQueueURL

func ExampleSQS_GetQueueURL() {
	svc := sqs.New(nil)

	params := &sqs.GetQueueURLInput{
		QueueName:              aws.String("String"), // Required
		QueueOwnerAWSAccountID: aws.String("String"),
	}
	resp, err := svc.GetQueueURL(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
开发者ID:navneet-flipkart,项目名称:confd,代码行数:27,代码来源:examples_test.go


示例5: deleteSQS

// deleteSQS removes a completed notification from the queue
func (c *config) deleteSQS(receiptHandle *string) error {
	q := sqs.New(&c.awsConfig)
	req := sqs.DeleteMessageInput{
		QueueURL:      aws.String(c.queueURL),
		ReceiptHandle: aws.String(*receiptHandle),
	}
	_, err := q.DeleteMessage(&req)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:Heuriskein,项目名称:traildash,代码行数:13,代码来源:traildash.go


示例6: deleteSQS

// deleteSQS removes a completed notification from the queue
func (c *config) deleteSQS(m *cloudtrailNotification) error {
	q := sqs.New(&c.awsConfig)
	req := sqs.DeleteMessageInput{
		QueueURL:      aws.String(c.queueURL),
		ReceiptHandle: aws.String(m.ReceiptHandle),
	}
	_, err := q.DeleteMessage(&req)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:rainmanh,项目名称:traildash,代码行数:13,代码来源:traildash.go


示例7: ExampleSQS_SendMessageBatch

func ExampleSQS_SendMessageBatch() {
	svc := sqs.New(nil)

	params := &sqs.SendMessageBatchInput{
		Entries: []*sqs.SendMessageBatchRequestEntry{ // Required
			&sqs.SendMessageBatchRequestEntry{ // Required
				ID:           aws.String("String"), // Required
				MessageBody:  aws.String("String"), // Required
				DelaySeconds: aws.Long(1),
				MessageAttributes: &map[string]*sqs.MessageAttributeValue{
					"Key": &sqs.MessageAttributeValue{ // Required
						DataType: aws.String("String"), // Required
						BinaryListValues: [][]byte{
							[]byte("PAYLOAD"), // Required
							// More values...
						},
						BinaryValue: []byte("PAYLOAD"),
						StringListValues: []*string{
							aws.String("String"), // Required
							// More values...
						},
						StringValue: aws.String("String"),
					},
					// More values...
				},
			},
			// More values...
		},
		QueueURL: aws.String("String"), // Required
	}
	resp, err := svc.SendMessageBatch(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
开发者ID:navneet-flipkart,项目名称:confd,代码行数:50,代码来源:examples_test.go


示例8: TestFlattenedTraits

func TestFlattenedTraits(t *testing.T) {
	s := sqs.New(nil)
	_, err := s.DeleteMessageBatch(&sqs.DeleteMessageBatchInput{
		QueueURL: aws.String("QUEUE"),
		Entries: []*sqs.DeleteMessageBatchRequestEntry{
			&sqs.DeleteMessageBatchRequestEntry{
				ID:            aws.String("TEST"),
				ReceiptHandle: aws.String("RECEIPT"),
			},
		},
	})

	assert.Error(t, err)
	assert.Equal(t, "InvalidAddress", err.Code())
	assert.Equal(t, "The address QUEUE is not valid for this endpoint.", err.Message())
}
开发者ID:ninefive,项目名称:confd,代码行数:16,代码来源:api_test.go


示例9: dequeue

// dequeue fetches an item from SQS
func (c *config) dequeue() (*cloudtrailNotificationRecord, error) {
	numRequested := 1
	q := sqs.New(&c.awsConfig)

	req := sqs.ReceiveMessageInput{
		QueueURL:            aws.String(c.queueURL),
		MaxNumberOfMessages: aws.Long(int64(numRequested)),
		WaitTimeSeconds:     aws.Long(20), // max allowed
	}
	resp, err := q.ReceiveMessage(&req)
	if err != nil {
		return nil, fmt.Errorf("SQS ReceiveMessage error: %s", err.Error())
	}
	//c.debug("Received %d messsage from SQS.", len(resp.Messages))
	if len(resp.Messages) > numRequested {
		return nil, fmt.Errorf("Expected %d but got %d messages.", numRequested, len(resp.Messages))
	} else if len(resp.Messages) == 0 {
		return nil, nil
	}
	m := resp.Messages[0]
	body := *m.Body

	not := sqsNotification{}
	if err := json.Unmarshal([]byte(body), &not); err != nil {
		return nil, fmt.Errorf("SQS message JSON error [id: %s]: %s", not.MessageID, err.Error())
	}

	n := cloudtrailNotification{}
	if not.Message == "CloudTrail validation message." { // swallow validation messages
		if err = c.deleteSQS(m.ReceiptHandle); err != nil {
			return nil, fmt.Errorf("Error deleting CloudTrail validation message [id: %s]: %s", not.MessageID, err.Error())
		}
		return nil, fmt.Errorf("Deleted CloudTrail validation message id %s", not.MessageID)
	} else if err := json.Unmarshal([]byte(not.Message), &n); err != nil {
		kerblowie(fmt.Sprintf("CloudTrail JSON error [id: %s]: %s", not.MessageID, err.Error()))

		//		return nil, fmt.Errorf("CloudTrail JSON error [id: %s]: %s", not.MessageID, err.Error())
	}
	record := n.Records[0]
	record.MessageID = not.MessageID
	record.ReceiptHandle = *m.ReceiptHandle
	b, err := json.Marshal(record)
	c.debug(string(b))
	return &record, nil
}
开发者ID:Heuriskein,项目名称:traildash,代码行数:46,代码来源:traildash.go


示例10: Exec

// Satisfies the Listener interface and places the event on an AWS SQS
func (this *Sqs) Exec(evt event.Event) {

	this.Log.Handler(this, &evt)

	url := magicString(this.Config.GetUrl(), evt)
	reg := magicString(this.Config.GetRegion(), evt)
	msg := magicString(this.Config.GetMessage(), evt)
	svc := sqs.New(&aws.Config{Region: reg})
	params := &sqs.SendMessageInput{
		MessageBody: aws.String(msg),
		QueueURL:    aws.String(url),
	}
	_, err := svc.SendMessage(params)

	if err != nil {
		this.Log.Error(err.Error())
		return
	}
}
开发者ID:hyprstack,项目名称:eevy,代码行数:20,代码来源:sqs.go


示例11: TestSendMessageChecksumInvalidNoValidation

func TestSendMessageChecksumInvalidNoValidation(t *testing.T) {
	s := sqs.New(&aws.Config{
		DisableParamValidation:  true,
		DisableComputeChecksums: true,
	})
	s.Handlers.Send.Clear()

	req, _ := s.SendMessageRequest(&sqs.SendMessageInput{
		MessageBody: aws.String("test"),
	})
	req.Handlers.Send.PushBack(func(r *aws.Request) {
		body := ioutil.NopCloser(bytes.NewReader([]byte("")))
		r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
		r.Data = &sqs.SendMessageOutput{
			MD5OfMessageBody: aws.String("000"),
			MessageID:        aws.String("12345"),
		}
	})
	err := req.Send()
	assert.NoError(t, err)
}
开发者ID:ninefive,项目名称:confd,代码行数:21,代码来源:checksums_test.go


示例12: ExampleSQS_ReceiveMessage

func ExampleSQS_ReceiveMessage() {
	svc := sqs.New(nil)

	params := &sqs.ReceiveMessageInput{
		QueueURL: aws.String("String"), // Required
		AttributeNames: []*string{
			aws.String("QueueAttributeName"), // Required
			// More values...
		},
		MaxNumberOfMessages: aws.Long(1),
		MessageAttributeNames: []*string{
			aws.String("MessageAttributeName"), // Required
			// More values...
		},
		VisibilityTimeout: aws.Long(1),
		WaitTimeSeconds:   aws.Long(1),
	}
	resp, err := svc.ReceiveMessage(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
开发者ID:navneet-flipkart,项目名称:confd,代码行数:37,代码来源:examples_test.go


示例13: TestSendMessageChecksum

	"io/ioutil"
	"net/http"
	"testing"

	"github.com/awslabs/aws-sdk-go/aws"
	"github.com/awslabs/aws-sdk-go/aws/awserr"
	"github.com/awslabs/aws-sdk-go/internal/test/unit"
	"github.com/awslabs/aws-sdk-go/service/sqs"
	"github.com/stretchr/testify/assert"
)

var _ = unit.Imported

var svc = func() *sqs.SQS {
	s := sqs.New(&aws.Config{
		DisableParamValidation: true,
	})
	s.Handlers.Send.Clear()
	return s
}()

func TestSendMessageChecksum(t *testing.T) {
	req, _ := svc.SendMessageRequest(&sqs.SendMessageInput{
		MessageBody: aws.String("test"),
	})
	req.Handlers.Send.PushBack(func(r *aws.Request) {
		body := ioutil.NopCloser(bytes.NewReader([]byte("")))
		r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
		r.Data = &sqs.SendMessageOutput{
			MD5OfMessageBody: aws.String("098f6bcd4621d373cade4e832627b4f6"),
			MessageID:        aws.String("12345"),
开发者ID:ninefive,项目名称:confd,代码行数:31,代码来源:checksums_test.go


示例14: init

func init() {
	Before("@sqs", func() {
		World["client"] = sqs.New(nil)
	})
}
开发者ID:ninefive,项目名称:confd,代码行数:5,代码来源:client.go


示例15: TestInterface

func TestInterface(t *testing.T) {
	assert.Implements(t, (*sqsiface.SQSAPI)(nil), sqs.New(nil))
}
开发者ID:ninefive,项目名称:confd,代码行数:3,代码来源:interface_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang storagegateway.New函数代码示例发布时间:2022-05-24
下一篇:
Golang sns.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