When fetching records from Kafka bootstrap servers, we can specify one consumer to subscribe to more than one topic. This can be done in the init function by passing a list of topics:
topics = ['kontext-events', 'other-events'] bootstrap_servers = 'localhost:9092' consumer = KafkaConsumer( *topics, client_id='local-test', bootstrap_servers=bootstrap_servers, auto_offset_reset='earliest' )
Alternatively, we can use subscribe()
function to subscribe to multiple topics. We can also regular expressions to match topics via patterns:
subscribe(topics=(), pattern=None, listener=None)