Using SEDA
The staged event-driven architecture (SEDA) refers to an approach to software architecture that decomposes a complex, event-driven application into a set of stages connected by queues. It avoids the high overhead associated with thread-based concurrency models (i.e. locking, unlocking, and polling for locks), and decouples event and thread scheduling from application logic.
For Java platform, Apache Camel provides support for SEDA component
These are some of the important properties of SEDA:
-
size
: Size of the queue. By default, its unbounded -
concurrentconsumers
: By default only one thread will be consuming from the queue -
blockWhenFull
: If the queue is full, the thread can be blocked. By default, an exception is thrown. In most scenario, you would want the thread to block.
Now, onto some code:
Below is an example of simple producer component:
And the consumer:
Here is the link to complete github repository