title: Getting the last message sent to a kafka topic
body: <p>I'm new to Kafka and working on a prototype to connect a proprietary streaming service into Kafka.</p>
  
  <p>I'm looking to get the key of the last message sent on a topic as our in-house stream consumer needs to logon with the ID of the last message it received when connecting.</p>
  
  <p>Is it possible, using either the KafkaProducer or a KafkaConsumer to do this?</p>
  
  <p>I've attempted to do the following using a Consumer, but when also running the console consumer I see messages replayed.</p>
  
  <pre><code>    // Poll so we know we're connected
      consumer.poll(100);
      // Get the assigned partitions
      Set&lt;TopicPartition&gt; assignedPartitions = consumer.assignment();
      // Seek to the end of those partitions
      consumer.seekToEnd(assignedPartitions);
  
      for(TopicPartition partition : assignedPartitions) {
          final long offset = consumer.committed(partition).offset();
          // Seek to the previous message
          consumer.seek(partition,offset - 1);
      }
  
      // Now get the last message
      ConsumerRecords&lt;String, String&gt; records = consumer.poll(100);
      for (ConsumerRecord&lt;String, String&gt; record : records) {
          lastKey = record.key();
      }
      consumer.close();
  </code></pre>
  
  <p>Is this expected behaviour or am I on the wrong path?</p>