In this day and age, there exists an increasing need for systems and architectures able to process spatio-temporal data in a timely way. As a result, this paper presents CEP-traj, a novel middleware to ease the development of real-time trajectory-based services based on the Complex Event Processing (CEP) paradigm. By means of an event-based approach, the present middleware is able to detect a set of generic patterns along with meaningful changes of an entity's movement. In order to prove its suitability and feasibility, a vessel abnormal-behaviour detection system has been developed on the basis of the middleware's features. Finally, both synthetic and real datasets have been used to test the accuracy and performance of the middleware and the detection system implemented on top of the Esper engine. © 2015 Elsevier Ltd. All rights reserved.