I was giving a partition index which was non-existing, i.e. I gave partition size as 3 and gave "template.send("target-partition",3,null,message)" 3 as the target partition, once I changed it to 0 or 1 or 2 the exception disappeared. Hope it helps.