コード例 #1
0
ファイル: example.go プロジェクト: Learnosity/go-kinesis
func getRecords(ksis kinesis.KinesisClient, 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 err != nil {
			time.Sleep(1000 * time.Millisecond)
			continue
		}

		if len(resp11.Records) > 0 {
			fmt.Printf("GetRecords Data BEGIN\n")
			for _, d := range resp11.Records {
				fmt.Printf("GetRecords Data: %v\n", string(d.GetData()))
			}
			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
		time.Sleep(1000 * time.Millisecond)
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: ramin/kisses
func getShardRecords(client kinesis.KinesisClient, streamName string, shardId string, messages chan []kinesis.GetRecordsRecords) {
	args := kinesis.NewArgs()
	args.Add("StreamName", streamName)
	args.Add("ShardId", shardId)
	args.Add("ShardIteratorType", "LATEST") // AT_SEQUENCE_NUMBER | AFTER_SEQUENCE_NUMBER | TRIM_HORIZON | LATEST
	resp, _ := client.GetShardIterator(args)

	shardIterator := resp.ShardIterator

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

		if err != nil {
			time.Sleep(3000 * time.Millisecond)
			continue
		}

		messages <- records.Records

		shardIterator = records.NextShardIterator
		time.Sleep(2000 * time.Millisecond)
	}
}