Developing a Java OSGi Application Using RabbitMQ Using PreparedStatement

I am developing an application that will run in an OSGi container (currently Equinox). It will receive messages through RabbitMQ and process them internally. The application will work continuously as a server. My current plan is for the RabbitMQ listener suite to configure its queues and place listeners on them, using QueueingConsumerand working in its threads. Students will access one or more processing services to process messages. Processors must make JDBC calls to access databases. I would like to be able to control the processing order of the processors. It would be nice to be able to add additional services later without retraining RabbitMQ listeners.

The problem I am facing is that messages may appear in batches or slowly. I would like to be able to use PreparedStatementto speed up access to the database, but I also do not want the connections to open for a long time until nothing happens. I thought about subclassing DefaultConsumerdirectly and letting it run threads in RabbitMQConnectionbut then I lose the ability to know when nothing happens. My initial idea was to completely parse message processors as OSGi services and each time grab a database connection from the pool each time it was called, but this loses the advantage of prepared statements. I am using the Tomcat JDBC pool, and it does not seem to have prepared caching statements. Also, I'm not sure how expensive it will be to create a prepared statement for each call, but it seems wasteful.

The best idea I came up with is for my listeners to work in a double loop. The outer loop waits for a message, then invokes the inner loop, which establishes database connections and prepared statements and starts until there are more messages for the specified timeout, then closes its connections and returns to the outer loop. I got this to work on one bit of processing, but I had problems with visualization, how to manage it if I have several processors that can have different prepared instructions.

Maybe I need to abandon the idea of ​​several services and hard code to handle my listeners.

Any suggestions? Thank!

+5
source share
1 answer

JDBC, ? . JDBC. JDBC API, Coordinator . "Aware" JDBC.

, DataSource . OSGi, , . .

, , , , . RabbitMQ, / .

, . , . ... , .

+1

All Articles