Multithreaded data processing pipeline with spring

I have an application that receives data packets and needs to parse, convert and store this data.

To increase throughput, I am trying to put the various steps into separate streams and allow the data stream through BlockingQueuebetween them.

Sort of:

(A) → (B) → (C) → ...

Until now, I have allowed to implement A, B, C Runnableand create them manually, providing I / O queues in the constructors.

The problem is that I need access to Spring services in A, B, C. Therefore, I annotated A, B, C with @Componentand @Scope("prototype"). I introduced them to another Service, which creates and sets up queues between them, callingthread.start(..)

Is there a way to do this better than Spring-like '? And how can I control the destruction of components, is it ideal to let them finish their current input queue?

EDIT 1: I followed Edwin Dalorzos' advice and played with Spring Integration, trying to archive my idea of ​​a single thread per message endpoint. I got multi-threaded work, but I can not limit the number of threads per endpoint. Created a small demo at https://github.com/taseroth/spring-integration-multithreaded

+4
source share

Source: https://habr.com/ru/post/1616803/


All Articles