Getting (2006, 'MySQL server has gone away error) in kafka consumer in my django application

119 Views Asked by At

I recently written a kafka consumer in my django project which is running in the background and there's a mysql query which reads inside the consumer and the process is very light as I don't have that much of data. But I'm getting (2006, 'MySQL server has gone away)

def job_listener():
    listener = KafkaConsumer(topic, group_id=group_id, bootstrap_servers=settings.KAFKA_BOOTSTRAP_SERVERS, auto_offset_reset=settings.KAFKA_AUTO_OFFSET_RESET, enable_auto_commit=settings.KAFKA_ENABLE_AUTO_COMMIT)

    for message in listener:
        try:
            data = json.loads(message.value)
            logger.info("Data Received {}".format(data))
        except Exception as e:
            data = None
            logger.error("Failed to parse the message with exception {}".format(e))
        if data is not None:
            try:
               job = Job.objects.get(pk=data['id'])
            except ObjectDoesNotExist:
               logger.error("Keyword doesn't exist with data {}".format(data))
                   
                listener.commit({TopicPartition(topic, message.partition): OffsetAndMetadata(message.offset+1, '')})
        except Exception as e:
            logger.error("Failed to read data {} with exception {}".format(data, e))
            listener.seek(TopicPartition(topic,
                                             message.partition), message.offset)
0

There are 0 best solutions below