private static Message ReadMessage(BrokerRouter router, string topic, int messageIndex, int maxBytes = 32768) { Message message = null; long offset = router.LatestOffset(topic) - (2 - messageIndex); List <Message> messages = router.Fetch(topic, 0, offset, maxBytes)?.Messages; if ((messages?.Count ?? 0) > 0) { message = messages?[0]; } if ((object)message == null) { throw new InvalidOperationException("No Kafka record to consume"); } return(message); }