Beispiel #1
0
        private static void Dequeue(OracleConnection connection, OracleAQQueue queue, OracleAQDequeueOptions dequeueOptions, int identifier)
        {
            var transaction = connection.BeginTransaction();

            try
            {
                var message = queue.Dequeue(dequeueOptions);
                if (message != null)
                {
                    var data = Encoding.UTF8.GetString((byte[])message.Payload);
                    Log.InfoFormat("[{0:D2}] : {1} ", identifier, data);
                    Interlocked.Increment(ref TotalMessagesReceived);
                }
            }
            catch (OracleException ex)
            {
                if (ex.Number != NoMessagesErrorCode)
                {
                    throw;
                }
                Log.InfoFormat("[{0:D2}] : NO DATA ", identifier);
            }
            transaction.Commit();
            transaction.Dispose();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;";

            try
            {
                OracleConnection _connObj = new OracleConnection(_connstring);
                // Create a new queue object
                OracleAQQueue _queueObj = new OracleAQQueue("EDZEHOO.JobsXML", _connObj);
                // Set the payload type to XML
                _queueObj.MessageType = OracleAQMessageType.Xml;
                _connObj.Open();
                OracleTransaction _txn = _connObj.BeginTransaction();
                // Dequeue the message.
                _queueObj.DequeueOptions.Visibility           = OracleAQVisibilityMode.OnCommit;
                _queueObj.DequeueOptions.Wait                 = 10;
                _queueObj.DequeueOptions.ProviderSpecificType = true;
                OracleAQMessage _deqMsg = _queueObj.Dequeue();
                OracleXmlType   _jobXML = (OracleXmlType)_deqMsg.Payload;
                MessageBox.Show("Dequeued Payload Data: \n" + _jobXML.Value);
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;";

            try
            {
                OracleConnection _connObj = new OracleConnection(_connstring);
                // Create a new queue object
                OracleAQQueue _queueObj = new OracleAQQueue("EDZEHOO.JobsQueue", _connObj);
                _connObj.Open();
                OracleTransaction _txn = _connObj.BeginTransaction();
                // Dequeue the message.
                _queueObj.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                _queueObj.DequeueOptions.Wait       = 10;
                // Here set the consumer name to the registered queue subscriber
                // This queue subscriber was registered when you setup the queue
                // in SQL*Plus
                _queueObj.DequeueOptions.ConsumerName = "JOHNDALY";
                OracleAQMessage _deqMsg = _queueObj.Dequeue();
                MessageBox.Show("Dequeued Payload Data: " + ConvertFromByteArray((byte[])_deqMsg.Payload) + "\n" + "Dequeued Payload Hex: " + ConvertToHexString((byte[])_deqMsg.Payload) + "\n" + "Message ID of Dequeued Payload : " + ConvertToHexString(_deqMsg.MessageId));
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;";

            try
            {
                OracleConnection _connObj = new OracleConnection(_connstring);
                // Create a new queue object
                OracleAQQueue _queueObj = new OracleAQQueue("EDZEHOO.MY_JOBS_QUEUE", _connObj);
                _connObj.Open();
                OracleTransaction _txn = _connObj.BeginTransaction();
                //The Visibility property OnCommit makes the dequeue part of the transaction
                //The Wait property specifies the number of seconds to wait for the Dequeue.
                //The default value of this property is set to wait forever
                _queueObj.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                _queueObj.DequeueOptions.Wait       = 10;
                // Dequeue the message.
                OracleAQMessage _deqMsg = _queueObj.Dequeue();
                MessageBox.Show("Dequeued Payload Data: " + ConvertFromByteArray((byte[])_deqMsg.Payload) + "\n" + "Dequeued Payload Hex: " + ConvertToHexString((byte[])_deqMsg.Payload) + "\n" + "Message ID of Dequeued Payload : " + ConvertToHexString(_deqMsg.MessageId) + "\n" + "Correlation : " + _deqMsg.Correlation);
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;";

            try
            {
                OracleConnection _connObj = new OracleConnection(_connstring);
                // Create a new queue object
                OracleAQQueue _queueObj = new OracleAQQueue("EDZEHOO.SmallJobs", _connObj);
                // Set the payload type to your UDT
                _queueObj.MessageType = OracleAQMessageType.Udt;
                _queueObj.UdtTypeName = "EDZEHOO.JOBS_TYPE";
                _connObj.Open();
                OracleTransaction _txn = _connObj.BeginTransaction();
                // Dequeue the message.
                _queueObj.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                _queueObj.DequeueOptions.Wait       = 10;
                OracleAQMessage _deqMsg = _queueObj.Dequeue();
                JobClass        _Data   = (JobClass)_deqMsg.Payload;
                MessageBox.Show(_Data.ToString());
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #6
0
        private IMessage Consume(OracleAQQueue queue)
        {
            OracleAQMessage aqMessage = null;

            try
            {
                //Deserialize payload
                aqMessage = queue.Dequeue();
            }
            catch (OracleException ex)
            {
            }
            return(default(IMessage));
        }
Beispiel #7
0
        private TransportMessage Receive(OracleAQQueue queue)
        {
            OracleAQMessage aqMessage = null;

            try
            {
                aqMessage = queue.Dequeue(this.dequeueOptions);
            }
            catch (OracleException ex)
            {
                if (ex.Number != OraCodes.TimeoutOrEndOfFetch)
                {
                    throw;
                }
            }

            return(TransportMessageMapper.DeserializeFromXml(aqMessage));
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;";

            try
            {
                OracleConnection _connObj = new OracleConnection(_connstring);
                // Create a new queue object
                OracleAQQueue _queueObj = new OracleAQQueue("EDZEHOO.MY_JOBS_QUEUE",
                                                            _connObj);
                _connObj.Open();
                // The Listen function is a blocking call - it will wait
                // indefinitely until a message is received.
                _queueObj.Listen(null);
                // Once we're here this means a message has been detected in the queue.
                // We can now proceed to dequeue that message
                OracleTransaction _txn = _connObj.BeginTransaction();
                // Dequeue the message.
                _queueObj.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                _queueObj.DequeueOptions.Wait       = 10;
                OracleAQMessage _deqMsg = _queueObj.Dequeue();
                MessageBox.Show("Dequeued Payload Data: " +
                                ConvertFromByteArray((byte[])_deqMsg.Payload) + "\n"
                                + "Dequeued Payload Hex: " +
                                ConvertToHexString((byte[])_deqMsg.Payload) + "\n"
                                + "Message ID of Dequeued Payload : " +
                                ConvertToHexString(_deqMsg.MessageId) + "\n" +
                                "Correlation : " + _deqMsg.Correlation);
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            // Create connection
            string           constr = "user id=scott;password=Pwd4Sct;data source=oracle";
            OracleConnection con    = new OracleConnection(constr);

            // Create queue
            OracleAQQueue queue = new OracleAQQueue("scott.test_q", con);

            try
            {
                // Open connection
                con.Open();

                // Begin txn for enqueue
                OracleTransaction txn = con.BeginTransaction();

                // Set message type for the queue
                queue.MessageType = OracleAQMessageType.Raw;

                // Prepare message and RAW payload
                OracleAQMessage enqMsg      = new OracleAQMessage();
                byte[]          bytePayload = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                enqMsg.Payload = bytePayload;

                // Prepare to Enqueue
                queue.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;

                // Enqueue message
                queue.Enqueue(enqMsg);

                Console.WriteLine("Enqueued Message Payload      : "
                                  + ByteArrayToString(enqMsg.Payload as byte[]));
                Console.WriteLine("MessageId of Enqueued Message : "
                                  + ByteArrayToString(enqMsg.MessageId));

                // Enqueue txn commit
                txn.Commit();

                // Begin txn for Dequeue
                txn = con.BeginTransaction();

                // Prepare to Dequeue
                queue.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                queue.DequeueOptions.Wait       = 10;

                // Dequeue message
                OracleAQMessage deqMsg = queue.Dequeue();

                Console.WriteLine("Dequeued Message Payload      : "
                                  + ByteArrayToString(deqMsg.Payload as byte[]));
                Console.WriteLine("MessageId of Dequeued Message : "
                                  + ByteArrayToString(deqMsg.MessageId));

                // Dequeue txn commit
                txn.Commit();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
            }
            finally
            {
                // Close/Dispose objects
                queue.Dispose();
                con.Close();
                con.Dispose();
            }
        }
 private void SetUpConnection()
 {
     try
     {
         RetryCount++;
         if (RetryCount > 60)
         {
             TraceSource.TraceEvent(TraceEventType.Critical, 5130, "Retry count exceeded: {0}", ConnectionInfo.ConnectionString);
             RetryCount = 30;
         }
         if (Connection != null)
         {
             Connection.StateChange -= Connection_StateChange;
             Queue.MessageAvailable -= Queue_Notification;
             try { Connection.Dispose(); }
             catch (Exception ex)
             {
                 TraceSource.TraceEvent(TraceEventType.Error, 5132, "{0}", ex);
             }
         }
         Connection = new OracleConnection(ConnectionInfo.ConnectionString);
         Connection.Open();
         CommitCommand             = Connection.CreateCommand();
         CommitCommand.CommandText = "COMMIT";
         Connection.StateChange   += Connection_StateChange;
         Queue = new OracleAQQueue("\"-DSL-\".NOTIFY_QUEUE", Connection, OracleAQMessageType.Udt, "-DSL-.NOTIFY_INFO_TYPE");
         Queue.NotificationConsumers         = new[] { ConsumerName };
         Queue.DequeueOptions.ConsumerName   = ConsumerName;
         Queue.DequeueOptions.DequeueMode    = OracleAQDequeueMode.Remove;
         Queue.DequeueOptions.DeliveryMode   = OracleAQMessageDeliveryMode.Persistent;
         Queue.DequeueOptions.Visibility     = OracleAQVisibilityMode.OnCommit;
         Queue.DequeueOptions.NavigationMode = OracleAQNavigationMode.NextTransaction;
         Queue.MessageAvailable += Queue_Notification;
         var converters = new List <OracleNotifyInfoConverter>();
         try
         {
             var deqOpt =
                 new OracleAQDequeueOptions
             {
                 Wait           = 1,
                 ConsumerName   = ConsumerName,
                 DequeueMode    = OracleAQDequeueMode.Remove,
                 DeliveryMode   = OracleAQMessageDeliveryMode.Persistent,
                 Visibility     = OracleAQVisibilityMode.OnCommit,
                 NavigationMode = OracleAQNavigationMode.NextTransaction
             };
             OracleAQMessage msg;
             while ((msg = Queue.Dequeue(deqOpt)) != null)
             {
                 var nic = msg.Payload as OracleNotifyInfoConverter;
                 if (nic != null)
                 {
                     converters.Add(nic);
                 }
             }
         }
         catch (OracleException ex)
         {
             var err = ex.Errors.Count > 0 ? ex.Errors[0] : null;
             if (err == null || err.Number != 25228)
             {
                 TraceSource.TraceEvent(TraceEventType.Information, 5133, "{0}", ex);
             }
         }
         if (converters.Count > 0)
         {
             ProcessNotifyConverters(converters);
         }
         RetryCount = 0;
     }
     catch (Exception ex)
     {
         RetryCount++;
         TraceSource.TraceEvent(TraceEventType.Error, 5134, "{0}", ex);
     }
 }
        private TransportMessage ReceiveFromQueue()
        {
            OracleAQDequeueOptions options = new OracleAQDequeueOptions
            {
                DequeueMode = OracleAQDequeueMode.Remove,
                Wait = this.SecondsToWaitForMessage,
                ProviderSpecificType = true,
            };

            TransportMessage transportMessage;

            using (OracleConnection conn = new OracleConnection(this.ConnectionString))
            {
                conn.Open();
                OracleAQQueue queue = new OracleAQQueue(this.inputQueueAddress, conn, OracleAQMessageType.Xml);
                OracleAQMessage aqMessage = null;
                try
                {
                    aqMessage = queue.Dequeue(options);
                }
                catch (OracleException ex)
                {
                    if (ex.Number != 25228)
                    {
                        throw;
                    }
                }

                // No message? That's okay
                if (null == aqMessage)
                {
                    return null;
                }

                Guid messageGuid = new Guid(aqMessage.MessageId);

                // the serialization has to go here since Oracle needs an open connection to
                // grab the payload from the message
                transportMessage = this.ExtractTransportMessage(aqMessage.Payload);
                transportMessage.Id = messageGuid.ToString();
                transportMessage.IdForCorrelation = aqMessage.Correlation;
            }

            Logger.DebugFormat("Received message from queue {0}", this.inputQueueAddress);

            // Set the correlation Id
            if (string.IsNullOrEmpty(transportMessage.IdForCorrelation))
            {
                transportMessage.IdForCorrelation = transportMessage.Id;
            }

            return transportMessage;
        }
        private TransportMessage Receive(OracleAQQueue queue)
        {
            OracleAQMessage aqMessage = null;
            try
            {
                aqMessage = queue.Dequeue(this.dequeueOptions);
            }
            catch (OracleException ex)
            {
                if (ex.Number != OraCodes.TimeoutOrEndOfFetch)
                {
                    throw;
                }
            }

            return TransportMessageMapper.DeserializeFromXml(aqMessage);
        }
        private TransportMessage ReceiveFromQueue()
        {
            OracleAQDequeueOptions options = new OracleAQDequeueOptions
            {
                DequeueMode = OracleAQDequeueMode.Remove,
                Wait = this.SecondsToWaitForMessage,
                ProviderSpecificType = true
            };

            OracleAQMessage aqMessage = null;
            TransportMessage transportMessage = null;

            this.transactionManager.RunInTransaction(
            (c) =>
            {
                OracleAQQueue queue = new OracleAQQueue(this.InputQueue, c, OracleAQMessageType.Xml);
                aqMessage = queue.Dequeue(options);

                // No message? That's okay
                if (null == aqMessage)
                    return;

                Guid messageGuid = new Guid(aqMessage.MessageId);

                // the serialization has to go here since Oracle needs an open connection to
                // grab the payload from the message
                transportMessage = this.ExtractTransportMessage(aqMessage.Payload);
            });

            Logger.DebugFormat("Received message from queue {0}", this.QueueTable);

            // Set the correlation Id
            if (String.IsNullOrEmpty(transportMessage.IdForCorrelation))
                transportMessage.IdForCorrelation = transportMessage.Id;

            return transportMessage;
        }
        protected override void ReceiveFromQueue()
        {
            OracleAQDequeueOptions options = new OracleAQDequeueOptions
            {
                DequeueMode = OracleAQDequeueMode.Remove,
                Wait = this.SecondsToWaitForMessage,
                ProviderSpecificType = true
            };

            OracleAQMessage aqMessage = null;
            TransportMessage transportMessage = null;

            try
            {
                GetTransactionManager().RunInTransaction(
                (c) =>
                {
                    OracleAQQueue queue = new OracleAQQueue(this.InputQueue, c, OracleAQMessageType.Xml);
                    aqMessage = queue.Dequeue(options);

                    // No message? That's okay
                    if (null == aqMessage)
                        return;

                    Guid messageGuid = new Guid(aqMessage.MessageId);
                    MessageId = messageGuid.ToString();

                    if (base.HandledMaxRetries(messageGuid.ToString()))
                    {
                        Logger.Error(string.Format("Message has failed the maximum number of times allowed, ID={0}.", MessageId));
                        this.MoveToErrorQueue(aqMessage);
                        base.OnFinishedMessageProcessing();

                        return;
                    }

                    base.OnStartedMessageProcessing();

                    // the serialization has to go here since Oracle needs an open connection to
                    // grab the payload from the message
                    try
                    {
                        if (base.UseXmlTransportSeralization)
                            transportMessage = this.ExtractXmlTransportMessage(aqMessage.Payload);
                        else
                            transportMessage = this.ExtractBinaryTransportMessage(aqMessage.Payload);
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Could not extract message data.", e);
                        this.MoveToErrorQueue(aqMessage);
                        base.OnFinishedMessageProcessing(); // don't care about failures here
                        return; // deserialization failed - no reason to try again, so don't throw
                    }

                });
            }
            catch (Exception e)
            {
                Logger.Error("Error in receiving message from queue.", e);
                throw;
            }

            // Set the correlation Id
            if (String.IsNullOrEmpty(transportMessage.IdForCorrelation))
                transportMessage.IdForCorrelation = transportMessage.Id;

            // care about failures here
            var exceptionNotThrown = OnTransportMessageReceived(transportMessage);
            // and here
            var otherExNotThrown = OnFinishedMessageProcessing();

            // but need to abort takes precedence - failures aren't counted here,
            // so messages aren't moved to the error queue.
            if (NeedToAbort)
                throw new AbortHandlingCurrentMessageException();

            if (!(exceptionNotThrown && otherExNotThrown)) //cause rollback
                throw new ApplicationException("Exception occured while processing message.");
        }