当前位置: 首页>>代码示例>>Golang>>正文


Golang kinesis.New函数代码示例

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


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

示例1: ExampleKinesis_DecreaseStreamRetentionPeriod

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

	svc := kinesis.New(sess)

	params := &kinesis.DecreaseStreamRetentionPeriodInput{
		RetentionPeriodHours: aws.Int64(1),             // Required
		StreamName:           aws.String("StreamName"), // Required
	}
	resp, err := svc.DecreaseStreamRetentionPeriod(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:realestate-com-au,项目名称:shush,代码行数:25,代码来源:examples_test.go

示例2: KinesisLoop

func KinesisLoop(event <-chan *d2k.Event, callback func(*d2k.Event) interface{}) {
	// main driver for pushing events to Kinesis

	svc := kinesis.New(&aws.Config{Region: "us-west-2"})

	// Wait... for stream to be ready
	for {
		params := &kinesis.DescribeStreamInput{
			StreamName: &KinesisStreamName,
		}
		if resp, err := svc.DescribeStream(params); err != nil {
			if awsErr, ok := err.(awserr.Error); ok {
				log.Fatalln("KinesisLoop:", awsErr.Code(), awsErr.Message())
			} else {
				log.Fatalln("KinesisLoop:", err)
			}
		} else if *resp.StreamDescription.StreamStatus == "ACTIVE" {
			break
		} else {
			log.Println("KinesisLoop:", KinesisStreamName, "not active")
			time.Sleep(1 * time.Second)
		}
	}

	for one_event := range event {
		msg := callback(one_event)
		if data, err := json.Marshal(msg); err != nil {
			log.Fatalln(err)
		} else {
			log.Println("KinesisLoop:", string(data))
			// TODO: send Kinesis event
		}
	}
}
开发者ID:yyljlyy,项目名称:agent,代码行数:34,代码来源:kinesis.go

示例3: Consume

//Consume gets data from a shard of an AWS Kinesis stream and puts them in a Go channel, once every second.
func Consume(shardID string, streamName string, region string, shardIteratorType string, eventChannel chan []byte) {
	svc := kinesis.New(session.New(), &aws.Config{Region: aws.String(region)})
	getShardIteratorParams := &kinesis.GetShardIteratorInput{
		ShardId:           aws.String(shardID),           // Required
		ShardIteratorType: aws.String(shardIteratorType), // Required
		StreamName:        aws.String(streamName),        // Required
	}
	shardIterator, err := svc.GetShardIterator(getShardIteratorParams)
	if err != nil {
		log.Panic(err)
	}

	nextShardIterator := shardIterator.ShardIterator
	for {
		getRecordsParams := &kinesis.GetRecordsInput{
			ShardIterator: nextShardIterator, // Required
			Limit:         aws.Int64(1000),
		}
		getRecordsResp, err := svc.GetRecords(getRecordsParams)
		if err != nil {
			log.Panic(err)
		}
		for _, record := range getRecordsResp.Records {
			eventChannel <- record.Data
		}
		nextShardIterator = getRecordsResp.NextShardIterator
		time.Sleep(time.Second)
	}
}
开发者ID:paybyphone,项目名称:kinchan,代码行数:30,代码来源:Consume.go

示例4: ExampleKinesis_SplitShard

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

	svc := kinesis.New(sess)

	params := &kinesis.SplitShardInput{
		NewStartingHashKey: aws.String("HashKey"),    // Required
		ShardToSplit:       aws.String("ShardId"),    // Required
		StreamName:         aws.String("StreamName"), // Required
	}
	resp, err := svc.SplitShard(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:realestate-com-au,项目名称:shush,代码行数:26,代码来源:examples_test.go

示例5: ExampleKinesis_UpdateShardCount

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

	svc := kinesis.New(sess)

	params := &kinesis.UpdateShardCountInput{
		ScalingType:      aws.String("ScalingType"), // Required
		StreamName:       aws.String("StreamName"),  // Required
		TargetShardCount: aws.Int64(1),              // Required
	}
	resp, err := svc.UpdateShardCount(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:realestate-com-au,项目名称:shush,代码行数:26,代码来源:examples_test.go

示例6: ExampleKinesis_PutRecord

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

	svc := kinesis.New(sess)

	params := &kinesis.PutRecordInput{
		Data:                      []byte("PAYLOAD"),          // Required
		PartitionKey:              aws.String("PartitionKey"), // Required
		StreamName:                aws.String("StreamName"),   // Required
		ExplicitHashKey:           aws.String("HashKey"),
		SequenceNumberForOrdering: aws.String("SequenceNumber"),
	}
	resp, err := svc.PutRecord(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:realestate-com-au,项目名称:shush,代码行数:28,代码来源:examples_test.go

示例7: NewKinesisBufferFlusher

// NewKinesisBufferFlusher returns a KinesisBufferFlusher configured with
// the stream name and partition key.
func NewKinesisBufferFlusher(name, partitionKey string) *KinesisBufferFlusher {
	sess := session.New()

	// Are we assuming a role?
	roleARN := conf.GetString("role-arn")
	if roleARN != "" {
		sess.Config.Credentials = stscreds.NewCredentials(sess, roleARN, func(o *stscreds.AssumeRoleProvider) {
			rsn := conf.GetString("role-session-name")
			if rsn != "" {
				o.RoleSessionName = rsn
			}
		})
	}

	region := conf.GetString("region")
	if region != "" {
		sess.Config.Region = aws.String(region)
	}

	return &KinesisBufferFlusher{
		Name:         aws.String(name),
		PartitionKey: partitionKey,
		kinesis:      kinesis.New(sess),
	}
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:27,代码来源:kinesis.go

示例8: ExampleKinesis_GetShardIterator

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

	svc := kinesis.New(sess)

	params := &kinesis.GetShardIteratorInput{
		ShardId:                aws.String("ShardId"),           // Required
		ShardIteratorType:      aws.String("ShardIteratorType"), // Required
		StreamName:             aws.String("StreamName"),        // Required
		StartingSequenceNumber: aws.String("SequenceNumber"),
		Timestamp:              aws.Time(time.Now()),
	}
	resp, err := svc.GetShardIterator(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:realestate-com-au,项目名称:shush,代码行数:28,代码来源:examples_test.go

示例9: ExampleKinesis_ListTagsForStream

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

	svc := kinesis.New(sess)

	params := &kinesis.ListTagsForStreamInput{
		StreamName:           aws.String("StreamName"), // Required
		ExclusiveStartTagKey: aws.String("TagKey"),
		Limit:                aws.Int64(1),
	}
	resp, err := svc.ListTagsForStream(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:realestate-com-au,项目名称:shush,代码行数:26,代码来源:examples_test.go

示例10: ExampleKinesis_EnableEnhancedMonitoring

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

	svc := kinesis.New(sess)

	params := &kinesis.EnableEnhancedMonitoringInput{
		ShardLevelMetrics: []*string{ // Required
			aws.String("MetricsName"), // Required
			// More values...
		},
		StreamName: aws.String("StreamName"), // Required
	}
	resp, err := svc.EnableEnhancedMonitoring(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:realestate-com-au,项目名称:shush,代码行数:28,代码来源:examples_test.go

示例11: ExampleKinesis_GetRecords

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

	svc := kinesis.New(sess)

	params := &kinesis.GetRecordsInput{
		ShardIterator: aws.String("ShardIterator"), // Required
		Limit:         aws.Int64(1),
	}
	resp, err := svc.GetRecords(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:realestate-com-au,项目名称:shush,代码行数:25,代码来源:examples_test.go

示例12: initialize

// Set defaults for all fields, initialize channel and client if not provided
func (stream *StreamWorker) initialize() error {
	if stream.IteratorType == "" {
		stream.IteratorType = ShardIteratorTypeLatest
	}

	if stream.BatchSize == 0 {
		stream.BatchSize = DefaultBatchSize
	}

	if stream.SleepTime == 0 {
		stream.SleepTime = DefaultSleepTime
	}

	if stream.Output == nil {
		stream.Output = make(chan Record)
	}

	if stream.State == nil {
		stream.State = make(chan WorkerState)
	}

	if stream.Client == nil {
		stream.Client = kinesis.New(stream.AwsConfig)
	}

	Logger.WithFields(log.Fields{
		"StreamWorker": stream,
		"AWS":          stream.AwsConfig,
	}).Debug("StreamWorker initialized")

	return nil
}
开发者ID:robbles,项目名称:kinesis_worker,代码行数:33,代码来源:kinesis_worker.go

示例13: Connect

func (k *KinesisOutput) Connect() error {
	// We attempt first to create a session to Kinesis using an IAMS role, if that fails it will fall through to using
	// environment variables, and then Shared Credentials.
	if k.Debug {
		log.Printf("kinesis: Establishing a connection to Kinesis in %+v", k.Region)
	}
	Config := &aws.Config{
		Region: aws.String(k.Region),
	}
	svc := kinesis.New(session.New(Config))

	KinesisParams := &kinesis.ListStreamsInput{
		Limit: aws.Int64(100),
	}

	resp, err := svc.ListStreams(KinesisParams)

	if err != nil {
		log.Printf("kinesis: Error in ListSteams API call : %+v \n", err)
	}

	if checkstream(resp.StreamNames, k.StreamName) {
		if k.Debug {
			log.Printf("kinesis: Stream Exists")
		}
		k.svc = svc
		return nil
	} else {
		log.Printf("kinesis : You have configured a StreamName %+v which does not exist. exiting.", k.StreamName)
		os.Exit(1)
	}
	return err
}
开发者ID:adithyabenny,项目名称:telegraf,代码行数:33,代码来源:kinesis.go

示例14: putRecord

// Put a single record.
func (kr KinesisRelay) putRecord(msg string) {
	kr.logger.Info.Println("Attempting to put record into stream")

	svc := kinesis.New(&kr.awsConfig)

	// TODO real partition key.
	params := &kinesis.PutRecordInput{
		StreamName:   aws.String(kr.config.Kinesis.StreamName),
		PartitionKey: aws.String("1"),
		Data:         []byte(msg),
	}

	resp, err := svc.PutRecord(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		kr.logger.Error.Printf("Error w/ PutRecord: %#v", err.Error())
		return
	}

	kr.logger.Trace.Printf("PutRecord response:  %#v", resp)

	kr.logger.Info.Println("Done putting record!")
}
开发者ID:syrneus,项目名称:kingologs,代码行数:26,代码来源:kinesis.go

示例15: TestMigrateStreams

func TestMigrateStreams(t *testing.T) {
	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		Log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}

	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      aws.String("us-east-1"),
	}
	client := kinesis.New(session.New(config))

	sm := StreamMigrator{
		Streams: []kinesis.CreateStreamInput{
			kinesis.CreateStreamInput{
				StreamName: aws.String(testDomain),
				ShardCount: aws.Int64(1),
			},
		},
		Client:  client,
		Timeout: 30,
	}

	sm.Migrate()
	sm.Migrate()

}
开发者ID:chadqueen,项目名称:swfsm,代码行数:27,代码来源:migrator_test.go


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