예제 #1
0
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
	}
}
예제 #2
0
파일: consumer.go 프로젝트: vly/haystack
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
}