OracleQueue - Dequeue method timeout

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
fad
Posts: 10
Joined: Wed 08 Oct 2014 13:08

OracleQueue - Dequeue method timeout

Post by fad » Fri 19 Jun 2015 12:24

Hi,
I'm using OracleQueue object with DequeueOptions.WaitTimeout = 30.

When I call OracleQueue.Dequeue method, the code returns after 30 seconds if the queue is empty.
In some case I need to stop the Dequeue method before timeout occur, how can I do it..?

Best regards,
Fad.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: OracleQueue - Dequeue method timeout

Post by Pinturiccio » Mon 22 Jun 2015 12:34

fad wrote:In some case I need to stop the Dequeue method before timeout occur, how can I do it..?
dotConnect for Oracle does not allow you to stop the Dequeue method execution, and you have to wait until it complete its execution or wait for the interval, specified in the DequeueOptions.WaitTimeout property.

We will analyze the possibility of implementing asynchronous execution for Enqueue and Dequeue methods but there is no timeframe.

As a workaround, you can execute the Dequeue method in a separate thread, and terminate this thread when you need to stop this method. You can use the BackgroundWorker class for this. For more information, please refer to https://msdn.microsoft.com/en-us/librar ... 10%29.aspx

fad
Posts: 10
Joined: Wed 08 Oct 2014 13:08

Re: OracleQueue - Dequeue method timeout

Post by fad » Wed 24 Jun 2015 07:59

Hi,
Ok, I've executed Dequeue method in a separate Thread.
To stopping Dequeue method I must call Thread.Abort method.

I'm looking forward to hearing from you news about asynchronous execution for Enqueue and Dequeue methods.

Best regards,
Fad.

mrbig
Posts: 9
Joined: Fri 31 Oct 2008 23:01

Re: OracleQueue - Dequeue method timeout

Post by mrbig » Wed 15 Jul 2015 22:37

Don't do thread abort to stop a sleeping dequeue. This will not work. The thread will not stop.

You should handle the timeout in a try catch block, eg.

Code: Select all

 
OracleQueueDequeueOptions myDequeueOptions = new OracleQueueDequeueOptions();
OracleQueue oracleDequeueQueue = new OracleQueue("DQ_SERVERMESSAGEQUEUE", myOracleConnection);
oracleDequeueQueue.DequeueOptions.WaitTimeout = 60;

OracleQueueMessage msg = null;

                    try
                    {
                        msg = oracleDequeueQueue.Dequeue();
                    }
                    catch (OracleException ex)
                    {
                        if (ex.Code == 25228)
                        {
                            logger.Debug("Queue timeout...");
                        }
                        else
                            throw ex;
                    }
                    
                    myOracleConnection.Close();
Remember you should also handle if oracle disappear during the time the code is sleeping in the dequeue i.e. if oracle disapears, connection lost, database crash, etc. If the connection is lost the dequeue function never returns.

You should have another thread checking if dequeue takes longer than 30 secs (in this example) and if it does, you should abort the thread and close and reopen a new connection to the database.

regards
/Klaus

Post Reply