卡夫卡消费者聆听两个事件/主题

时间:2020-07-28 08:08:54

标签: node.js apache-kafka kafka-consumer-api

有什么办法可以消耗两个主题并等待这两个事件继续消耗吗?

1 个答案:

答案 0 :(得分:0)

有什么办法可以消耗两个主题吗?

您可以在Kafka使用者中使用多个主题。如果您使用的是KafkaJS,那么这里是example,下面是一个代码段

// Subscribe can be called several times
await consumer.connect()

await consumer.subscribe({ topic: 'topic-B' })
await consumer.subscribe({ topic: 'topic-C' })

// Alternatively, you can subscribe to multiple topics at once using a RegExp:
await consumer.connect()

await consumer.subscribe({ topic: /topic-(eu|us)-.*/i })

请注意,使用者将不匹配在订阅后

创建的主题