问题
I have an Amazon Kinesis stream, consisting of multiple shards. The number of shards, and therefore the number of consumers, is not a constant.
There is an infrequent type of event that I want broadcasted to every consumer on the stream.
Is there a way for a producer to broadcast a record, i.e. to discover the shards and put the record on each one?
回答1:
You can do this! Kind of...
The trick it to use the parameter "ExplicitHashKey".
This lets you set the hash key used for the record, and therefore lets you chose what shard your data is going on.
You can then call
aws kinesis describe-stream --stream-name name-of-your-stream
to get info about each shard including what hash range each shard covers.
Then you only need to send your data to each shard (with PutRecord or PutRecords) and you are all set.
Unfortunately, there is no "broadcast" but you can easily write a Lambda to send the same data to each shard using the ExplicitHashKey parameter.
Another solution is to use separate streams and write out to each one.
来源:https://stackoverflow.com/questions/34883551/amazon-kinesis-put-record-to-every-shard