开发者

How to consume data from AWS Kinesis fanout using nodejs @aws-sdk/client-kinesis lib v3?

How to consume data from AWS Kinesis fanout using nodejs @aws-sdk/client-kinesis v3 lib? I registered a StreamConsumer and got a connection to a shard, but how do I consume data?

const client = new KinesisClient({ region });
//recover a consumer or create a new one
const { Consumers } = await client.send(new ListStreamConsumersCommand({ StreamARN }));

let consumer = Consumers.find((x) => x.ConsumerName == ConsumerName);
if (!consumer) {
  const { Consumer } = await client.send(new RegisterStreamConsumerCommand({ StreamARN, ConsumerName }));
  consumer = Consumer;
}

//subscribe to shard
const { EventStream } = await client.send(
  new SubscribeToShardCommand({
    ConsumerARN: consumer.ConsumerARN,
    ShardId: shardId,
    StartingPosition: { Type: 'TRIM_HORIZON' },
  }),
);

Log of Consumers and EventStream looks like this:

Consumers: [
  {
    ConsumerARN: 'arn:aws:kinesis:ap-south-1:123123123:stream/test-stream/consumer/test-client:234234234',
    ConsumerCreationTimestamp: 2022-12-07T04:33:20.000Z,
    ConsumerName: 'test-client',
    ConsumerStatus: 'ACT开发者_JAVA百科IVE'
  }
]

EventStream:
{
  [Symbol(Symbol.asyncIterator)]: [AsyncGeneratorFunction: [Symbol.asyncIterator]]
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜