1

I have a confluent-kafka consumer which will be running once in a day. while its running i just wants to get one last message from the topic. I have below code, but is not fetching the last message, just reading the messages other than the last message. My confluent-kafka consumer code looks like:

cfg = {
            'bootstrap.servers': host,
            'group.id': groupName,
            'api.version.request': False,
            'enable.auto.commit': True,
            'session.timeout.ms': 6000,
            'default.topic.config': {'auto.offset.reset': 'largest'},
            'security.protocol': 'SSL',
            'ssl.key.password': 'pswd',
            'ssl.ca.location': certPath,
        }
        C = Consumer(cfg)
        C.assign([TopicPartition(topicName, 1)])
        C.subscribe([topicName])
        msgList=[]       
        while True:
            msg = C.poll(6.0)
            if msg:
               jsonmsg= json.loads(msg.value())
               if jsonmsg[expectedValue]==eventId:
                    msgList.append(eventId)
                    break

where eventId is the value present on the last published message. Do I need to include any parameter or Am I missing something in configs ? Any help would be appreciated.

kaviya .P
  • 469
  • 3
  • 11
  • 27
  • This should read some event, but it's unclear to me why you think it'll be the most recent... Did you want to seek to the end? Also, you shouldn't subscribe and assign; just subscribe if you want all partitions – OneCricketeer Oct 22 '21 at 13:29

0 Answers0