I work with a piece of software (WMS) where Oracle PL/SQL packages are a huge part of the business logic. I would like to introduce a way to asynchronously do some calculations which are triggered by an event. For some better understanding, we are to introduce some freight estimation which should be calculated whenever a new order is submitted to the database. It is vital that the calculation is made on another session/thread than the original one committing the order.
My first approach was to use an advanced queue (AQ). Whenever an order is created, a message is enqueued to the AQ. Then I got three ways of processing the message (at least I have come up with):
Using an infinite DBMS Scheduler job I will create a job that runs for ever which will call the dequeue method on the AQ. In this way, the job is able to process the message and do some calculation. Pros: It will process the message immediately it has been submitted. Cons: An infinitely running job is not easily stopped.
Using a DBMS Scheduler job running every X seconds Pros: It is possible to stop the job Cons: It will not process the message immediately
Using a trigger on the AQ to create a new job This is another approach. With this approach I can create a trigger that fires whenever a message is enqueued to the AQ. The logic of the trigger will then create a DBMS Scheduler job that dequeues the AQ and auto drops. Pros: It runs somewhat immediately Cons: The database will be creating and dropping jobs all the time. I am not sure if this is an issue, but it gut-feeling about this is not great.
Anyone with any experience with this?