public static Integer getIntegerPartitionKey(OutgoingMessageEnvelope envelope, List<PartitionInfo> partitions) {
    int numPartitions = partitions.size();
    return abs(envelope.getPartitionKey().hashCode()) % numPartitions;
  }
Partition key in the envelope must not be null.
samza-kafka/src/main/java/org/apache/samza/util/KafkaUtil.java