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


Golang sqs.New函數代碼示例

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


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


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