Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Async Processing

I am currently developing a system that uses allot of async processing. The transfer of information is done using Queues. So one process will put info in the Queue (and terminate) and another will pick it up and process it. My implementation leaves me facing a number of challenges and I am interested in what everyone's approach is to these problems (in terms of architecture as well as libraries).

Let me paint the picture. Lets say you have three processes:

Process A -----> Process B
                      |
Process C <-----------|

So Process A puts a message in a queue and ends, Process B picks up the message, processes it and puts it in a "return" queue. Process C picks up the message and processes it.

  1. How does one handle Process B not listening or processing messages off the Queue? Is there some JMS type method that prevents a Producer from submitting a message when the Consumer is not active? So Process A will submit but throw an exception.
  2. Lets say Process C has to get a reply with in X minutes, but Process B has stopped (for any reason), is there some mechanism that enforces a timeout on a Queue? So guaranteed reply within X minutes which would kick off Process C.

Can all of these matters be handled using a dead letter Queue of some sort? Should I maybe be doing this all manually with timers and check. I have mentioned JMS but I am open to anything, in fact I am using Hazelcast for the Queues.

Please note this is more of a architectural question, in terms of available java technologies and methods, and I do feel this is a proper question.

Any suggestions will be greatly appreciated.

Thanks

like image 764
Paul Avatar asked Jul 11 '26 05:07

Paul


2 Answers

IMHO, The simplest solution is to use an ExecutorService, or a solution based on an executor service. This supports a queue of work, scheduled tasks (for timeouts).

It can also work in a single process. (I believe Hazelcast supports distributed ExecutorService)

like image 98
Peter Lawrey Avatar answered Jul 13 '26 20:07

Peter Lawrey


It seems to me that the type of questions you're asking are "smells" that queues and async processing may not be the best tools for your situation.

1) That defeats a purpose of a queue. Sounds like you need a synchronous request-response process.

2) Process C is not getting a reply generally speaking. It's getting a message from a queue. If there is a message in the queue and the Process C is ready then it will get it. Process C could decide that the message is stale once it gets it, for example.

like image 26
Yuriy Zubarev Avatar answered Jul 13 '26 18:07

Yuriy Zubarev