Call middleware when processing messages.