byte[] bytes = getBytes(msgValue);
byte[] keyBytes = getBytes(msgKey);
// check the checksum of message.
// If message has partition key, need to construct it with Key for checkSum to match
Message messageWithKey = new Message(bytes,keyBytes);
Message messageWithoutKey = new Message(bytes);
long checksum = key.getChecksum();
if (checksum != messageWithKey.checksum() && checksum != messageWithoutKey.checksum()) {
throw new ChecksumException("Invalid message checksum : MessageWithKey : "
+ messageWithKey.checksum() + " MessageWithoutKey checksum : "
+ messageWithoutKey.checksum()
+ ". Expected " + key.getChecksum(),
key.getOffset());
}
The code will handle the case when the partitionId is encoded along with the message when you are sending it to Kafka.
Not sure if you are passing on any more details.
In either case you need to look at how you are encoding your messages.