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


Golang go-kinesis.Kinesis類代碼示例

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


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

示例1: CreateStream

// CreateStream creates a new stream
func CreateStream(k *kinesis.Kinesis, tempStreamName string, shards int) bool {
	if err := k.CreateStream(tempStreamName, shards); err != nil {
		return false
	}

	// wait for Stream ready state
	timeout := make(chan bool, 30)
	resp := &kinesis.DescribeStreamResp{}
	log.Printf("Waiting for stream to be created")
	for {
		args := kinesis.NewArgs()
		args.Add("StreamName", tempStreamName)
		resp, _ = k.DescribeStream(args)
		log.Printf(".")

		if resp.StreamDescription.StreamStatus != "ACTIVE" {
			time.Sleep(4 * time.Second)
			timeout <- true
		} else {
			break
		}
	}

	return true
}
開發者ID:vly,項目名稱:haystack,代碼行數:26,代碼來源:producer_api.go

示例2: getRecords

func getRecords(ksis *kinesis.Kinesis, streamName, ShardId string) {
	args := kinesis.NewArgs()
	args.Add("StreamName", streamName)
	args.Add("ShardId", ShardId)
	args.Add("ShardIteratorType", "TRIM_HORIZON")
	resp10, _ := ksis.GetShardIterator(args)

	shardIterator := resp10.ShardIterator

	for {
		args = kinesis.NewArgs()
		args.Add("ShardIterator", shardIterator)
		resp11, err := ksis.GetRecords(args)

		if len(resp11.Records) > 0 {
			fmt.Printf("GetRecords Data BEGIN\n")
			for _, d := range resp11.Records {
				res, err := d.GetData()
				fmt.Printf("GetRecords Data: %v, err: %v\n", string(res), err)
			}
			fmt.Printf("GetRecords Data END\n")
		} else if resp11.NextShardIterator == "" || shardIterator == resp11.NextShardIterator || err != nil {
			fmt.Printf("GetRecords ERROR: %v\n", err)
			break
		}

		shardIterator = resp11.NextShardIterator
	}
}
開發者ID:bohford,項目名稱:go-kinesis,代碼行數:29,代碼來源:example.go

示例3: GetMessages

func GetMessages(k *kinesis.Kinesis, streamName string, shardID string) (out [][]byte, ok bool) {
	shardIterator := GetShardIterator(k, streamName, shardID)

	for {
		args := kinesis.NewArgs()
		args.Add("ShardIterator", shardIterator)
		recordResp, err := k.GetRecords(args)
		if err == nil {

			if len(recordResp.Records) > 0 {
				for _, d := range recordResp.Records {
					res, err := d.GetData()
					if err != nil {
						LogFile(err.Error())
					}
					//fmt.Printf("GetRecords Data: %v, err: %v\n", string(res), err)
					out = append(out, res)
				}
			} else {

				break
			}
		}

		shardIterator = recordResp.NextShardIterator

	}
	return out, true
}
開發者ID:vly,項目名稱:haystack,代碼行數:29,代碼來源:consumer.go

示例4: GetShardIterator

func GetShardIterator(k *kinesis.Kinesis, streamName string, shardId string) string {
	args := kinesis.NewArgs()
	args.Add("StreamName", streamName)
	args.Add("ShardId", shardId)
	args.Add("ShardIteratorType", "TRIM_HORIZON")
	a, _ := k.GetShardIterator(args)
	return a.ShardIterator
}
開發者ID:vly,項目名稱:haystack,代碼行數:8,代碼來源:consumer.go

示例5: SendMessage

// SendMessage generates a new JSON blob and sends to a stream
func SendMessage(k *kinesis.Kinesis, streamName string, msg *Message, comms chan bool) {
	args := kinesis.NewArgs()
	args.Add("StreamName", streamName)
	args.Add("PartitionKey", fmt.Sprintf("partitionKey-%d", 1))
	if data, ok := msg.ToJSON(); ok {
		args.AddData(data)
		if _, err := k.PutRecord(args); err == nil {
			comms <- true
			return
		}
	}
	log.Println("Failed to send message")
	comms <- false
	return
}
開發者ID:vly,項目名稱:haystack,代碼行數:16,代碼來源:producer_api.go

示例6: CheckStream

// CheckStream verifies whether a stream already exists
func CheckStream(k *kinesis.Kinesis, streamname string) bool {
	args := kinesis.NewArgs()
	args.Add("StreamName", streamname)
	temp, err := k.ListStreams(args)
	if err != nil {
		log.Println("Could not obtain list of streams.")
	} else {

		for _, b := range temp.StreamNames {
			if b == streamname {
				return true
			}
		}
	}
	return false
}
開發者ID:vly,項目名稱:haystack,代碼行數:17,代碼來源:producer_api.go

示例7: DeleteStream

// DeleteStream deletes an existing stream
func DeleteStream(k *kinesis.Kinesis, streamName string) bool {
	if err := k.DeleteStream(streamName); err == nil {
		return true
	}
	return false
}
開發者ID:vly,項目名稱:haystack,代碼行數:7,代碼來源:producer_api.go


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