views:

184

answers:

1

Scenerio:

Function A() ->creates the message and puts the message in the queue

Listener -> checks constantly if theres a message in the queue and sends it to the service to process it and get the result and inserts the result into db

Function B() ->gets the result from the db

Suppose the result from the service hasn't come out yet and function b() is called now,the record for tht message id would return null from the db as the result hasnt been inserted yet.

How do you handle such scenerio?

+3  A: 

If function B is dependent on the service completing processing, then it should run off a message queue as well.

When the service finishes, it should write a new message to another queue. Another listener should pick it up and call function B.

If function B is initiated by a user interface gesture, the UI just needs to convey that a required process hasn't completed and disallow the action until it does.

Jeff Sternal
Queue or event - either way it needs to be triggered by an appropriate mechanism once the listener has finished inserting the event into the database.
Murph
but at the code level code gets executed line by line thn how would u do that coz those functions would have been executed before u get the result from the db, r u suggesting that to display a message box "Please wait,your request is still under process" and then check again from the db if the record has been inserted or not, but what if its still not inserted ?
Something like that - you can either require the user to refresh the user interface manually (with a refresh button, or something similar) or add a timer to your UI that checks the database at some reasonable interval and updates it when function B completes. If the user chooses to close the program before it finishes (or navigate away from the web page depending on your scenario), that's their business.
Jeff Sternal