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

Golang sqs.New函数代码示例

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

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



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

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


示例2: ExampleSQS_ChangeMessageVisibilityBatch

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

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

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
开发者ID:ColourboxDevelopment,项目名称:aws-sdk-go,代码行数:26,代码来源: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 always return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

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


示例4: ExampleSQS_ChangeMessageVisibility

func ExampleSQS_ChangeMessageVisibility() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := sqs.New(sess)

	params := &sqs.ChangeMessageVisibilityInput{
		QueueUrl:          aws.String("String"), // Required
		ReceiptHandle:     aws.String("String"), // Required
		VisibilityTimeout: aws.Int64(1),         // Required
	}
	resp, err := svc.ChangeMessageVisibility(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:26,代码来源:examples_test.go


示例5: ExampleSQS_AddPermission

func ExampleSQS_AddPermission() {
	svc := sqs.New(session.New())

	params := &sqs.AddPermissionInput{
		AWSAccountIds: []*string{ // Required
			aws.String("String"), // Required
			// More values...
		},
		Actions: []*string{ // Required
			aws.String("String"), // Required
			// More values...
		},
		Label:    aws.String("String"), // Required
		QueueUrl: aws.String("String"), // Required
	}
	resp, err := svc.AddPermission(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

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


示例6: ExampleSQS_DeleteMessageBatch

func ExampleSQS_DeleteMessageBatch() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := sqs.New(sess)

	params := &sqs.DeleteMessageBatchInput{
		Entries: []*sqs.DeleteMessageBatchRequestEntry{ // Required
			{ // Required
				Id:            aws.String("String"), // Required
				ReceiptHandle: aws.String("String"), // Required
			},
			// More values...
		},
		QueueUrl: aws.String("String"), // Required
	}
	resp, err := svc.DeleteMessageBatch(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:31,代码来源:examples_test.go


示例7: ExampleSQS_RemovePermission

func ExampleSQS_RemovePermission() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := sqs.New(sess)

	params := &sqs.RemovePermissionInput{
		Label:    aws.String("String"), // Required
		QueueUrl: aws.String("String"), // Required
	}
	resp, err := svc.RemovePermission(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:25,代码来源:examples_test.go


示例8: Get

func (q *SQSQueue) Get() (*ScriptCommand, error) {
	sess := session.New(&aws.Config{
		Region: aws.String(viper.GetString("queue.region")),
		Credentials: credentials.NewStaticCredentials(
			viper.GetString("credentials.aws_access_id"),
			viper.GetString("credentials.aws_secret"),
			"",
		),
	})

	svc := sqs.New(sess)

	params := &sqs.ReceiveMessageInput{
		QueueUrl:              aws.String(viper.GetString("queue.url")),
		AttributeNames:        []*string{},
		MaxNumberOfMessages:   aws.Int64(1),
		MessageAttributeNames: []*string{},
		VisibilityTimeout:     aws.Int64(1),
	}

	resp, err := svc.ReceiveMessage(params)
	if len(resp.Messages) > 0 {
		dec := json.NewDecoder(strings.NewReader(*resp.Messages[0].Body))
		var cmd *ScriptCommand
		err = dec.Decode(&cmd)
		cmd.Receipt = *resp.Messages[0].ReceiptHandle
		return cmd, err
	} else {
		return nil, nil
	}
}
开发者ID:cgmarquis07,项目名称:Conduit,代码行数:31,代码来源:sqs.go


示例9: ExampleSQS_AddPermission

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

	params := &sqs.AddPermissionInput{
		AWSAccountIDs: []*string{ // Required
			aws.String("String"), // Required
			// More values...
		},
		Actions: []*string{ // Required
			aws.String("String"), // Required
			// More values...
		},
		Label:    aws.String("String"), // Required
		QueueURL: aws.String("String"), // Required
	}
	resp, err := svc.AddPermission(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 always return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.Prettify(resp))
}
开发者ID:Talos208,项目名称:aws-sdk-go,代码行数:35,代码来源:examples_test.go


示例10: pollMessage

func pollMessage(queueUrl string) {
	sqsClient := sqs.New(&aws.Config{Region: aws.String("us-east-1")})

	req := &sqs.ReceiveMessageInput{QueueURL: aws.String(queueUrl)}

	result, err := sqsClient.ReceiveMessage(req)

	if nil != err {
		panic(err)
	} else {
		parsedResponse, err := gabs.ParseJSON([]byte(*result.Messages[0].Body))

		if nil != err {
			panic(err)
		}

		var payload string

		payload = parsedResponse.Path("Message").Data().(string)

		fmt.Println(unpretty(payload))

		deleteRequest := &sqs.DeleteMessageInput{QueueURL: aws.String(queueUrl), ReceiptHandle: aws.String(*result.Messages[0].ReceiptHandle)}

		_, err = sqsClient.DeleteMessage(deleteRequest)

		if nil != err {
			panic(err)
		}
	}
}
开发者ID:exceleratesystems,项目名称:sqstail,代码行数:31,代码来源:main.go


示例11: waitForResult

// waitForResult waits for the job to be processed and the job result to be added
// to the job result SQS queue.  This will pool the SQS queue for job results until
// a job result matches the file it uploaded. When a match is found the job result
// will also be deleted from the queue, and its status written to the console.
// If the job result doesn't match the file uploaded by this client, the message
// will be ignored, so another client could received it.
func waitForResult(bucket, filename, resultQueueURL string) {
	svc := sqs.New(nil)
	for {
		resp, err := svc.ReceiveMessage(&sqs.ReceiveMessageInput{
			QueueUrl:          aws.String(resultQueueURL),
			VisibilityTimeout: aws.Int64(0),
			WaitTimeSeconds:   aws.Int64(20),
		})
		if err != nil {
			log.Println("Failed to receive mesasge", err)
			time.Sleep(30 * time.Second)
			continue
		}

		for _, msg := range resp.Messages {
			result := &wordfreq.JobResult{}
			if err := json.Unmarshal([]byte(aws.StringValue(msg.Body)), result); err != nil {
				log.Println("Failed to unmarshal message", err)
				continue
			}

			if result.Job.Bucket != bucket || result.Job.Key != filename {
				continue
			}

			printResult(result)
			svc.DeleteMessage(&sqs.DeleteMessageInput{
				QueueUrl:      aws.String(resultQueueURL),
				ReceiptHandle: msg.ReceiptHandle,
			})
			return
		}
	}
}
开发者ID:Tsingson1988,项目名称:aws-go-wordfreq-sample,代码行数:40,代码来源:main.go


示例12: main

func main() {
	flag.Parse()

	config, err := LoadConfig(configFilePath)
	if err != nil {
		log.Fatalf("Error loading config file: %s", err)
	}

	logger := buildLogger(config.LogLevel)

	awsConfig := aws.NewConfig().WithRegion(config.SQSConfig.Region)
	awsSession := session.New(awsConfig)

	sqssvc := sqs.New(awsSession)
	queue := awssqs.NewSQSQueue(sqssvc, logger)

	iamsvc := iam.New(awsSession)
	user := awsiam.NewIAMUser(iamsvc, logger)

	serviceBroker := sqsbroker.New(config.SQSConfig, queue, user, logger)

	credentials := brokerapi.BrokerCredentials{
		Username: config.Username,
		Password: config.Password,
	}

	brokerAPI := brokerapi.New(serviceBroker, logger, credentials)
	http.Handle("/", brokerAPI)

	fmt.Println("SQS Service Broker started on port " + port + "...")
	http.ListenAndServe(":"+port, nil)
}
开发者ID:cf-platform-eng,项目名称:sqs-broker,代码行数:32,代码来源:main.go


示例13: main

func main() {
	// Create SQS instance
	s := sqs.New(session.New(), &aws.Config{Region: aws.String("us-west-2")})

	// Create Queue instance
	q, err := queue.New(s, "test")
	if err != nil {
		log.Fatal(err)
	}

	for {
		messages, err := q.ReceiveMessage(option.MaxNumberOfMessages(10))
		if err != nil {
			log.Println(err)
			continue
		}

		if len(messages) > 0 {
			for _, m := range messages {
				log.Println(*m.Body)
				q.DeleteMessage(m.ReceiptHandle)
			}
		}

	}
}
开发者ID:noliva,项目名称:go-aws-sqs,代码行数:26,代码来源:main.go


示例14: main

func main() {
	var err error

	// connect to the database
	dbconn, err = sql.Open("postgres", PACKAGEBUG_DB)
	if err != nil {
		log.Fatal(err)
	}

	// make sure the database up
	err = dbconn.Ping()
	if err != nil {
		log.Fatal(err)
	}

	// set up aws SDK credentials & config
	cred := credentials.NewEnvCredentials()
	_, err = cred.Get()
	if err != nil {
		log.Fatal(err)
	}
	config := aws.NewConfig()
	config.Credentials = cred
	config.Endpoint = &PACKAGEBUG_SQS_ENDPOINT
	config.Region = &PACKAGEBUG_SQS_REGION

	sqsconn = sqs.New(config)
	// dispatch jobs once a day
	for {
		<-time.After(24 * time.Hour)
		go dispatchJobs()
	}
}
开发者ID:pyk,项目名称:packagebug-discpatcher,代码行数:33,代码来源:main.go


示例15: LifecycleEventQueueURL

// LifecycleEventQueueURL inspects the current autoscaling group and returns
// the URL of the first suitable lifecycle hook queue.
func (s *Cluster) LifecycleEventQueueURL() (string, error) {
	asg, err := s.AutoscalingGroup()
	if err != nil {
		return "", err
	}

	autoscalingSvc := autoscaling.New(s.AwsSession)
	resp, err := autoscalingSvc.DescribeLifecycleHooks(&autoscaling.DescribeLifecycleHooksInput{
		AutoScalingGroupName: asg.AutoScalingGroupName,
	})
	if err != nil {
		return "", err
	}

	sqsSvc := sqs.New(s.AwsSession)
	for _, hook := range resp.LifecycleHooks {
		if !strings.HasPrefix(*hook.NotificationTargetARN, "arn:aws:sqs:") {
			continue
		}
		arnParts := strings.Split(*hook.NotificationTargetARN, ":")
		queueName := arnParts[len(arnParts)-1]
		queueOwnerAWSAccountID := arnParts[len(arnParts)-2]

		resp, err := sqsSvc.GetQueueUrl(&sqs.GetQueueUrlInput{
			QueueName:              &queueName,
			QueueOwnerAWSAccountId: &queueOwnerAWSAccountID,
		})
		if err != nil {
			return "", err
		}
		return *resp.QueueUrl, nil
	}
	return "", ErrLifecycleHookNotFound
}
开发者ID:crewjam,项目名称:ec2cluster,代码行数:36,代码来源:lifecycle.go


示例16: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %v -queue-url <queue-url> [-region <region>] [-delete] [mesages...]\n", os.Args[0])
		flag.PrintDefaults()
	}
	flag.Parse()

	// queue url is required
	if *queueURL == "" {
		fmt.Fprintln(os.Stderr, "-queue-url is required")
		os.Exit(1)
	}

	// create an SQS client object
	svc := sqs.New(session.New(&aws.Config{Region: region}))

	msgs := flag.Args()
	if len(msgs) > 0 {
		if err := sendMessage(svc, msgs...); err != nil {
			log.Fatal(err)
		}
	}

	count := int64(10)
	rmsgs, err := receiveMessage(svc, count)
	if err != nil {
		log.Fatal(err)
	}

	if *delete {
		if err := deleteMessage(svc, rmsgs...); err != nil {
			log.Fatal(err)
		}
	}
}
开发者ID:skatsuta,项目名称:aws-sdk-go-sample,代码行数:35,代码来源:main.go


示例17: SQS_SendMessage

func SQS_SendMessage(body string, mobileNumber string) {
	svc := sqs.New(&aws.Config{Region: amazonRegion})
	params := &sqs.SendMessageInput{
		MessageBody:  aws.String(body),
		QueueURL:     aws.String(amazonQueueURL),
		DelaySeconds: aws.Long(1),
		MessageAttributes: map[string]*sqs.MessageAttributeValue{
			"MobileNumber": {
				DataType:    aws.String("String"),
				StringValue: aws.String(mobileNumber),
			},
			"CreatingTime": {
				DataType:    aws.String("String"),
				StringValue: aws.String(time.Now().String()),
			},
		},
	}
	resp, err := svc.SendMessage(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			fmt.Println(err.Error())
		}
	}
	fmt.Println(awsutil.StringValue(resp))
}
开发者ID:AurelienMassiot,项目名称:SMSsender-Twilio-AmazonSQS,代码行数:31,代码来源:add_msg_to_queue.go


示例18: NewCustomResourceProvisioner

// NewCustomResourceProvisioner returns a new CustomResourceProvisioner with an
// sqs client configured from config.
func NewCustomResourceProvisioner(db *sql.DB, config client.ConfigProvider) *CustomResourceProvisioner {
	p := &CustomResourceProvisioner{
		Provisioners: make(map[string]customresources.Provisioner),
		sendResponse: customresources.SendResponse,
		sqs:          sqs.New(config),
	}

	p.add("Custom::InstancePort", &InstancePortsProvisioner{
		ports: lb.NewDBPortAllocator(db),
	})

	p.add("Custom::ECSService", &ECSServiceResource{
		ecs: ecs.New(config),
	})

	store := &dbEnvironmentStore{db}
	p.add("Custom::ECSEnvironment", newECSEnvironmentProvisioner(&ECSEnvironmentResource{
		environmentStore: store,
	}))
	p.add("Custom::ECSTaskDefinition", newECSTaskDefinitionProvisioner(&ECSTaskDefinitionResource{
		ecs:              ecs.New(config),
		environmentStore: store,
	}))

	return p
}
开发者ID:brianz,项目名称:empire,代码行数:28,代码来源:cloudformation.go


示例19: ExampleSQS_GetQueueUrl

func ExampleSQS_GetQueueUrl() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := sqs.New(sess)

	params := &sqs.GetQueueUrlInput{
		QueueName:              aws.String("String"), // Required
		QueueOwnerAWSAccountId: aws.String("String"),
	}
	resp, err := svc.GetQueueUrl(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:25,代码来源:examples_test.go


示例20: SQS

// Return a singleton SQS service instance
func SQS() *sqs.SQS {
	if sqsService == nil {
		if accessKey() != "" && secretKey() != "" && region() != "" {
			sqsService = sqs.New(session.New(&aws.Config{
				Region:      aws.String(region()),
				Credentials: credentials.NewStaticCredentials(accessKey(), secretKey(), ""),
			}))
		} else {
			log.Printf("no AWS environment variables found; defaulting to EC2 instance profile and region %s.\n", region())
			sqsService = sqs.New(session.New(&aws.Config{
				Region: aws.String(region()),
			}))
		}
	}
	return sqsService
}
开发者ID:gpitfield,项目名称:aws,代码行数:17,代码来源:sqs.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang sqs.SQS类代码示例发布时间:2022-05-24
下一篇:
Golang sns.SNS类代码示例发布时间: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