@@ -36,13 +36,14 @@ type Kinesis struct {
36
36
type KinesisClient interface {
37
37
CreateStream (StreamName string , ShardCount int ) error
38
38
DeleteStream (StreamName string ) error
39
- MergeShards (args * RequestArgs ) error
40
- SplitShard (args * RequestArgs ) error
41
- ListStreams (args * RequestArgs ) (resp * ListStreamsResp , err error )
42
39
DescribeStream (args * RequestArgs ) (resp * DescribeStreamResp , err error )
43
- GetShardIterator (args * RequestArgs ) (resp * GetShardIteratorResp , err error )
44
40
GetRecords (args * RequestArgs ) (resp * GetRecordsResp , err error )
41
+ GetShardIterator (args * RequestArgs ) (resp * GetShardIteratorResp , err error )
42
+ ListStreams (args * RequestArgs ) (resp * ListStreamsResp , err error )
43
+ MergeShards (args * RequestArgs ) error
45
44
PutRecord (args * RequestArgs ) (resp * PutRecordResp , err error )
45
+ PutRecords (args * RequestArgs ) (resp * PutRecordsResp , err error )
46
+ SplitShard (args * RequestArgs ) error
46
47
}
47
48
48
49
// Initialize new client for AWS Kinesis
@@ -63,12 +64,15 @@ func makeParams(action string) map[string]string {
63
64
64
65
// RequestArgs store params for request
65
66
type RequestArgs struct {
66
- params map [string ]interface {}
67
+ params map [string ]interface {}
68
+ Records []PutRecordsRecord
67
69
}
68
70
69
71
// NewFilter creates a new Filter.
70
72
func NewArgs () * RequestArgs {
71
- return & RequestArgs {make (map [string ]interface {})}
73
+ return & RequestArgs {
74
+ params : make (map [string ]interface {}),
75
+ }
72
76
}
73
77
74
78
// Add appends a filtering parameter with the given name and value(s).
@@ -124,14 +128,21 @@ func (kinesis *Kinesis) query(params map[string]string, data interface{}, resp i
124
128
}
125
129
126
130
// request
127
- request , err := http .NewRequest ("POST" , fmt .Sprintf ("https://kinesis.%s.amazonaws.com" , kinesis .Region ), bytes .NewReader (jsonData ))
131
+ request , err := http .NewRequest (
132
+ "POST" ,
133
+ fmt .Sprintf ("https://kinesis.%s.amazonaws.com" , kinesis .Region ),
134
+ bytes .NewReader (jsonData ),
135
+ )
136
+
128
137
if err != nil {
129
138
return err
130
139
}
140
+
131
141
// headers
132
142
request .Header .Set ("Content-Type" , "application/x-amz-json-1.1" )
133
143
request .Header .Set ("X-Amz-Target" , fmt .Sprintf ("Kinesis_%s.%s" , kinesis .Version , params [ACTION_KEY ]))
134
144
request .Header .Set ("User-Agent" , "Golang Kinesis" )
145
+
135
146
// response
136
147
response , err := kinesis .client .Do (request )
137
148
if err != nil {
@@ -292,7 +303,7 @@ type GetRecordsRecords struct {
292
303
SequenceNumber string
293
304
}
294
305
295
- func (r GetRecordsRecords ) GetData () ( []byte ) {
306
+ func (r GetRecordsRecords ) GetData () []byte {
296
307
return r .Data
297
308
}
298
309
@@ -331,3 +342,46 @@ func (kinesis *Kinesis) PutRecord(args *RequestArgs) (resp *PutRecordResp, err e
331
342
}
332
343
return
333
344
}
345
+
346
+ // PutRecords puts multiple data records into an Amazon Kinesis stream from a producer
347
+ // more info http://docs.aws.amazon.com/kinesis/latest/APIReference/API_PutRecords.html
348
+ func (kinesis * Kinesis ) PutRecords (args * RequestArgs ) (resp * PutRecordsResp , err error ) {
349
+ params := makeParams ("PutRecords" )
350
+ resp = & PutRecordsResp {}
351
+ args .Add ("Records" , args .Records )
352
+ err = kinesis .query (params , args .params , resp )
353
+
354
+ if err != nil {
355
+ return nil , err
356
+ }
357
+ return
358
+ }
359
+
360
+ // PutRecordsResp stores the information that provides by PutRecord API call
361
+ type PutRecordsResp struct {
362
+ FailedRecordCount int
363
+ Records []PutRecordsRespRecord
364
+ }
365
+
366
+ // RecordResp stores individual Record information provided by PutRecords API call
367
+ type PutRecordsRespRecord struct {
368
+ ErrorCode string
369
+ ErrorMessage string
370
+ SequenceNumber string
371
+ ShardId string
372
+ }
373
+
374
+ // Add data and partition for sending multiple Records to Kinesis in one API call
375
+ func (f * RequestArgs ) AddRecord (value []byte , partitionKey string ) {
376
+ r := PutRecordsRecord {
377
+ Data : value ,
378
+ PartitionKey : partitionKey ,
379
+ }
380
+ f .Records = append (f .Records , r )
381
+ }
382
+
383
+ // PutRecordsRecord stores the Data and PartitionKey for batch calls to Kinesis API
384
+ type PutRecordsRecord struct {
385
+ Data []byte
386
+ PartitionKey string
387
+ }
0 commit comments