Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Message Queue library

by sundialsvc4 (Abbot)
on Jun 21, 2018 at 22:20 UTC ( #1217138=note: print w/replies, xml ) Need Help??


in reply to Message Queue library

I suggest that your logic can be simplified as follows:   there is a queue, containing records that are waiting to be sent, and there is one separate global variable that contains the block which we are now trying to send.   So the logic becomes something like this ...

SendDataEvent(Data toSend) { $toSend->serial = $serial_number_counter++; Enqueue(toSend); if ( !defined($block_awaiting_reply) ) { $block_awaiting_reply = Dequeue() send($block_awaiting_reply); } } OnDataReceivedEvent(Data reply) { if ( defined($block_awaiting_reply)) { if ((reply->status == OK) && (reply->serial == $block_awaiting_reply->serial)) { // OK response received to last block sent $block_awaiting_reply = undef; // optional } else { // block was rejected send it again resend($block_awaiting_reply); return; } $block_awaiting_reply = dequeue(); // should be non-blocking if ($block_awaiting_reply != undef) { send($block_awaiting_reply); } }

For simplicity I am assuming some kind of serialized event-driven logic so that there will be no race against $block_awaiting_reply or $serial_number_counter.

As you see, this variable is undef if nothing has been sent to the receiver; otherwise, it contains the one block that must be successfully replied-to.   The sender will continue to send that block until that block is acknowledged.   A more-robust system might do additional checks such as making sure that the receiver is not sending acknowledgements back in the wrong sequence or duplicated.   Notice that this design dis-ambiguates between blocks that are in the process of being sent and those that have not yet been sent:   if they are in the queue, they have not been sent.

Replies are listed 'Best First'.
Re^2: Message Queue library
by pwagyi (Scribe) on Jun 22, 2018 at 08:23 UTC

    Sorry for the late reply. The events (SendDataEvent and OnDataReceived) are not in the same process. The producer can produce data and add to queue at any time And reply may be received after an hour or a day... so I've background job to fetch replies and triggers (OnDataReceived)...

    That's why I think I need persistence queue with some locking mechanism. Since there is potential that reply is received while new Data is generated, etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1217138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2019-10-15 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?