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());
            }
        }
Esempio n. 2
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());
            }
        }
Esempio n. 3
0
 private static void DequeueTest_NoListen(int identifier)
 {
     try
     {
         var connection = new OracleConnection(ConnectionString);
         connection.Open();
         var queue = new OracleAQQueue("SCHEDULE_QUEUE", connection)
         {
             MessageType    = OracleAQMessageType.Raw,
             EnqueueOptions =
             {
                 Visibility   = OracleAQVisibilityMode.OnCommit,
                 DeliveryMode = OracleAQMessageDeliveryMode.Persistent
             }
         };
         var dequeueOptions = new OracleAQDequeueOptions
         {
             Visibility     = OracleAQVisibilityMode.OnCommit,
             NavigationMode = OracleAQNavigationMode.NextMessage,
             DequeueMode    = OracleAQDequeueMode.Remove,
             DeliveryMode   = OracleAQMessageDeliveryMode.Persistent,
             Wait           = -1
         };
         while (true)
         {
             Dequeue(connection, queue, dequeueOptions, identifier);
         }
     }
     catch (Exception e)
     {
         Log.Error(e.Message, e);
         throw;
     }
 }
Esempio n. 4
0
        private static void EnqueueData(OracleConnection connection, int messageCount, int delay)
        {
            Log.InfoFormat("Enqueue {0} message(s) with delay seconds {1}", messageCount, delay);
            var group = Guid.NewGuid().ToString();

            for (int index = 1; index <= messageCount; index++)
            {
                var data    = string.Format("Test message : {0} - {1}", group, index);
                var message = new OracleAQMessage
                {
                    Payload     = Encoding.UTF8.GetBytes(data),
                    Correlation = index.ToString(),
                    Delay       = delay
                };

                var queue = new OracleAQQueue("SCHEDULE_QUEUE", connection)
                {
                    MessageType    = OracleAQMessageType.Raw,
                    EnqueueOptions =
                    {
                        Visibility   = OracleAQVisibilityMode.OnCommit,
                        DeliveryMode = OracleAQMessageDeliveryMode.Persistent
                    }
                };
                Log.InfoFormat("Enqueueing {0}", data);
                var transaction = connection.BeginTransaction();
                queue.Enqueue(message);
                transaction.Commit();
            }
        }
Esempio n. 5
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 button1_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);
                _connObj.Open();
                OracleTransaction _txn = _connObj.BeginTransaction();
                // Set payload type to XML
                _queueObj.MessageType = OracleAQMessageType.Xml;
                // Create a new message object
                OracleAQMessage _msg    = new OracleAQMessage();
                OracleXmlType   _jobXML = new OracleXmlType(_connObj, "<JOB><JOBID>J1234</JOBID><JOBNAME>Feed Snuppy</JOBNAME></JOB>");
                _msg.Payload = _jobXML;
                // Enqueue the message
                _queueObj.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                _queueObj.Enqueue(_msg);
                // Display the payload data that was enqueued
                MessageBox.Show("Payload Data : \n" + _jobXML.Value);
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void button3_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();
                _queueObj.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                _queueObj.DequeueOptions.Wait       = 10;
                //Register the callback function
                _queueObj.MessageAvailable += new
                                              OracleAQMessageAvailableEventHandler(IncomingMessageCallback);
                _txn.Commit();
                MessageBox.Show("Notification registered. Entering loop...");
                // Loop while waiting for notification
                while (_notified == false)
                {
                    System.Threading.Thread.Sleep(2000);
                }
                _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.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());
            }
        }
Esempio n. 9
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());
            }
        }
Esempio n. 10
0
        private ReceiveResult TryReceive(OracleAQQueue queue)
        {
            var result = new ReceiveResult();

            using (var ts = new TransactionScope(TransactionScopeOption.Required, this.transactionOptions))
            {
                queue.Connection.EnlistTransaction(Transaction.Current);
                result.Message = this.Receive(queue);

                try
                {
                    if (result.Message == null || this.tryProcessMessage(result.Message))
                    {
                        // NOTE: We explicitly calling Dispose so that we force any exception to not bubble,
                        // eg Concurrency/Deadlock exception.
                        ts.Complete();
                        ts.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    result.Exception = ex;
                }

                return(result);
            }
        }
Esempio n. 11
0
        private void Action(object obj)
        {
            var cancellationToken = (CancellationToken)obj;

            while (!cancellationToken.IsCancellationRequested)
            {
                var result = new ReceiveResult();

                try
                {
                    using (var connection = new OracleConnection(this.ConnectionString))
                    {
                        using (var queue = new OracleAQQueue(this.workQueue, connection, OracleAQMessageType.Xml))
                        {
                            connection.Open();

                            this.SetupClientInfo(connection);

                            queue.Listen(null);

                            result = this.TryReceive(queue);
                        }
                    }
                }
                finally
                {
                    if (result.Message != null)
                    {
                        this.endProcessMessage(result.Message, result.Exception);
                    }
                }

                this.circuitBreaker.Success();
            }
        }
        public OracleAQQueue GetOracleQueue(string queueName)
        {
            OracleConnection connection = new OracleConnection("WRITE_CONNECTIONSTRING_HERE");

            connection.Open();

            OracleAQQueue queue = new OracleAQQueue(queueName, connection);

            queue.MessageType = OracleAQMessageType.Xml;
            queue.EnqueueOptions.Visibility = OracleAQVisibilityMode.Immediate;

            return(queue);
        }
Esempio n. 13
0
        private IMessage Consume(OracleAQQueue queue)
        {
            OracleAQMessage aqMessage = null;

            try
            {
                //Deserialize payload
                aqMessage = queue.Dequeue();
            }
            catch (OracleException ex)
            {
            }
            return(default(IMessage));
        }
        private void button1_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();
                // Set payload type
                _queueObj.MessageType = OracleAQMessageType.Raw;
                // Create an array of OracleAQMessage objects
                OracleAQMessage[] _msgs = new OracleAQMessage[2];
                // Fill the array with strings
                String[] Data = new String[2];
                Data[0]  = "HELLO, HOW ARE YOU!";
                Data[1]  = "... AND WHAT'S YOUR NAME?";
                _msgs[0] = new OracleAQMessage(ConvertToByteArray(Data[0]));
                _msgs[1] = new OracleAQMessage(ConvertToByteArray(Data[1]));
                // Enqueue the message - take note that we're using the EnqueueArray
                // function now
                _queueObj.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                _queueObj.EnqueueArray(_msgs);
                // Display the payload data that was enqueued
                for (int i = 0; i < 2; i++)
                {
                    MessageBox.Show("Payload Data : " + Data[i] + "\n" +
                                    "Payload Hex value : " +
                                    ConvertToHexString((byte[])_msgs[i].Payload) + "\n" +
                                    "Message ID : " + ConvertToHexString(_msgs[i].MessageId));
                }
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 15
0
        public OracleDatabaseQuery(
            OracleConnection connection,
            OracleTransaction transaction)
        {
            Contract.Requires(connection != null);

            this.Connection       = connection;
            this.ConnectionString = connection.ConnectionString;
            this.Transaction      = transaction;
            Queue =
                new Lazy <OracleAQQueue>(() =>
            {
                var q = new OracleAQQueue("\"-DSL-\".NOTIFY_QUEUE", Connection, OracleAQMessageType.Udt, "-DSL-.NOTIFY_INFO_TYPE");
                q.EnqueueOptions.Visibility   = OracleAQVisibilityMode.OnCommit;
                q.EnqueueOptions.DeliveryMode = OracleAQMessageDeliveryMode.Persistent;
                return(q);
            });
        }
Esempio n. 16
0
		public OracleDatabaseQuery(
			OracleConnection connection,
			OracleTransaction transaction)
		{
			Contract.Requires(connection != null);

			this.Connection = connection;
			this.ConnectionString = connection.ConnectionString;
			this.Transaction = transaction;
			Queue =
				new Lazy<OracleAQQueue>(() =>
				{
					var q = new OracleAQQueue("\"-NGS-\".NOTIFY_QUEUE", Connection, OracleAQMessageType.Udt, "-NGS-.NOTIFY_INFO_TYPE");
					q.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
					q.EnqueueOptions.DeliveryMode = OracleAQMessageDeliveryMode.Persistent;
					return q;
				});
		}
Esempio n. 17
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));
        }
        public override void Send(TransportMessage m, String destination)
        {
            GetTransactionManager().RunInTransaction(c =>
            {
                // Set the time from the source machine when the message was sent
                m.TimeSent = DateTime.UtcNow;
                OracleAQQueue queue = new OracleAQQueue(destination, c, OracleAQMessageType.Xml);
                queue.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;

                using (var stream = new MemoryStream())
                {
                    base.SerializeTransportMessage(m, stream);
                    OracleAQMessage aqMessage = new OracleAQMessage(Encoding.UTF8.GetString(stream.ToArray()));
                    aqMessage.Correlation  = m.CorrelationId;
                    queue.Enqueue(aqMessage);
                }
            });
        }
        /// <summary>
        /// /// Sends the given message to the address.
        /// /// </summary>
        /// /// <param name="message">Message to send.</param>
        /// /// <param name="address">Message destination address.</param>
        public void Send(TransportMessage message, Address address)
        {
            using (OracleConnection conn = new OracleConnection(this.ConnectionString))
            {
                conn.Open();

                // Set the time from the source machine when the message was sent
                OracleAQQueue queue = new OracleAQQueue(OracleAqsUtilities.NormalizeQueueName(address), conn, OracleAQMessageType.Xml);
                queue.EnqueueOptions.Visibility = Transaction.Current == null ? OracleAQVisibilityMode.Immediate : OracleAQVisibilityMode.OnCommit;

                using (var stream = new MemoryStream())
                {
                    this.SerializeToXml(message, stream);
                    OracleAQMessage aqMessage = new OracleAQMessage(Encoding.UTF8.GetString(stream.ToArray()));
                    aqMessage.Correlation = message.CorrelationId;
                    queue.Enqueue(aqMessage);
                }
            }
        }
Esempio n. 20
0
        private static void DequeueTest_UsingListen(int identifier)
        {
            try
            {
                var aqueueAgent = new [] { new OracleAQAgent(null, "CS_SCHEDULER.SCHEDULE_QUEUE") };
                var connection  = new OracleConnection(ConnectionString);
                connection.Open();
                var queue = new OracleAQQueue("SCHEDULE_QUEUE", connection)
                {
                    MessageType    = OracleAQMessageType.Raw,
                    EnqueueOptions =
                    {
                        Visibility   = OracleAQVisibilityMode.OnCommit,
                        DeliveryMode = OracleAQMessageDeliveryMode.Persistent
                    }
                };

                var dequeueOptions = new OracleAQDequeueOptions
                {
                    Visibility     = OracleAQVisibilityMode.OnCommit,
                    NavigationMode = OracleAQNavigationMode.NextMessage,
                    DequeueMode    = OracleAQDequeueMode.Remove,
                    DeliveryMode   = OracleAQMessageDeliveryMode.Persistent,
                    Wait           = -1
                };

                while (true)
                {
                    var agent = OracleAQQueue.Listen(connection, aqueueAgent, 1);
                    if (agent != null)
                    {
                        Dequeue(connection, queue, dequeueOptions, identifier);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message, e);
                Log.ErrorFormat("Identifier : {0}", identifier);
                Environment.Exit(0);
            }
        }
        private void button3_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();
                // Set payload type
                _queueObj.MessageType = OracleAQMessageType.Raw;
                // Create a new message object
                OracleAQMessage _msg = new OracleAQMessage();
                String          Data = "HELLO, HOW ARE YOU!";
                _msg.Payload = ConvertToByteArray(Data);
                // Enqueue the message
                _queueObj.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                // Register the subscriber at the message-level using the
                // OracleAQMessage.Recipients property
                OracleAQAgent[] agent = new OracleAQAgent[1];
                agent[0]        = new OracleAQAgent("RONFRICKE");
                _msg.Recipients = agent;
                _msg.SenderId   = new OracleAQAgent("EDZEHOO");
                _queueObj.Enqueue(_msg);
                // Display the payload data that was enqueued
                MessageBox.Show("Payload Data : " + Data + "\n" +
                                "Payload Hex value : " + ConvertToHexString((byte[])_msg.Payload) + "\n" +
                                "Message ID : " + ConvertToHexString(_msg.MessageId));
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 22
0
        private void button1_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();
                // Set payload type to RAW (byte array)
                _queueObj.MessageType = OracleAQMessageType.Raw;
                // Create a new message object
                OracleAQMessage _msg = new OracleAQMessage();
                String          Data = "HELLO, HOW ARE YOU!";
                _msg.Payload = ConvertToByteArray(Data);
                //You can also attach additional custom data to a message via the
                //Correlation property
                _msg.Correlation = "MY ADDITIONAL MISC DATA";
                //The Visibility property OnCommit makes the enqueue part of a transaction
                _queueObj.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                // Enqueue the message
                _queueObj.Enqueue(_msg);
                // Display the payload data that was enqueued
                MessageBox.Show("Payload Data : " + Data + "\n" +
                                "Payload Hex value : " + ConvertToHexString((byte[])_msg.Payload) +
                                "\n" + "Message ID : " + ConvertToHexString(_msg.MessageId) + "\n" +
                                "Correlation : " + _msg.Correlation);
                _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.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());
            }
        }
        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();
                _queueObj.DequeueOptions.Visibility           = OracleAQVisibilityMode.OnCommit;
                _queueObj.DequeueOptions.Wait                 = 10;
                _queueObj.DequeueOptions.ProviderSpecificType = true;
                // Dequeue the messages – take note that you can specify the number of
                // messages you wish to retrieve from the queue
                OracleAQMessage[] _deqMsgs = _queueObj.DequeueArray(2);
                for (int i = 0; i < _deqMsgs.Length; i++)
                {
                    // If you enqueued a byte array, the dequeued object is an
                    // OracleBinary object. You can retrieve the byte array using the
                    // OracleBinary.Value property
                    OracleBinary _payload = (OracleBinary)_deqMsgs[i].Payload;
                    MessageBox.Show("Dequeued Payload Data: " +
                                    ConvertFromByteArray(_payload.Value) + "\n"
                                    + "Dequeued Payload Hex: " +
                                    ConvertToHexString(_payload.Value) + "\n");
                }
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 25
0
        private void button1_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);
                _connObj.Open();
                OracleTransaction _txn = _connObj.BeginTransaction();
                // Set the payload type to your UDT
                _queueObj.MessageType = OracleAQMessageType.Udt;
                _queueObj.UdtTypeName = "EDZEHOO.JOBS_TYPE";
                // Create a new message object
                OracleAQMessage _msg = new OracleAQMessage();
                // Create an instance of JobClass and pass it in as the payload for the // message
                JobClass _job = new JobClass();
                _job.JobID          = "J1234";
                _job.JobName        = "Feed Snuppy";
                _job.JobPrice       = 15;
                _job.JobDescription = "Feed Rice Crispies twice a day";
                _msg.Payload        = _job;
                // Enqueue the message
                _queueObj.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                _queueObj.Enqueue(_msg);
                // Display the payload data that was enqueued
                MessageBox.Show("Payload Data : " + _job.ToString());
                _txn.Commit();
                _queueObj.Dispose();
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 private void MoveToErrorQueue(OracleAQMessage message)
 {
     if (!String.IsNullOrEmpty(base.ErrorQueue))
     {
         GetTransactionManager().RunInTransaction(c =>
         {
             OracleAQQueue queue = new OracleAQQueue(base.ErrorQueue, c, OracleAQMessageType.Xml);
             queue.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
             queue.Enqueue(message);
         });
     }
 }
        public void Send(TransportMessage message, Address address)
        {
            var transactionManager = new OracleTransactionManager(this.ConnectionString);

            transactionManager.RunInTransaction(c =>
            {
                // Set the time from the source machine when the message was sent
                OracleAQQueue queue = new OracleAQQueue(address.Queue, c, OracleAQMessageType.Xml);
                queue.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
                using (var stream = new MemoryStream())
                {
                    this.SerializeToXml(message, stream);
                    OracleAQMessage aqMessage = new OracleAQMessage(Encoding.UTF8.GetString(stream.ToArray()));
                    aqMessage.Correlation = message.CorrelationId;
                    queue.Enqueue(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.");
        }
 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 ReceiveResult TryReceive(OracleAQQueue queue)
        {
            var result = new ReceiveResult();

            using (var ts = new TransactionScope(TransactionScopeOption.Required, this.transactionOptions))
            {
                queue.Connection.EnlistTransaction(Transaction.Current);
                result.Message = this.Receive(queue);

                try
                {
                    if (result.Message == null || this.tryProcessMessage(result.Message))
                    {
                        // NOTE: We explicitly calling Dispose so that we force any exception to not bubble,
                        // eg Concurrency/Deadlock exception.
                        ts.Complete();
                        ts.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    result.Exception = ex;
                }

                return result;
            }
        }
        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);
        }
        /// <summary>
        /// Sends the given message to the address.
        /// </summary>
        /// <param name="message">Message to send.</param>
        /// <param name="address">Message destination address.</param>
        public void Send(TransportMessage message, Address address)
        {
            try
            {
                var queueConnectionString = this.DefaultConnectionString;
                if (ConnectionStringCollection.Keys.Contains(address.Queue))
                {
                    queueConnectionString = ConnectionStringCollection[address.Queue];
                }

                using (OracleConnection conn = new OracleConnection(queueConnectionString))
                {
                    conn.Open();

                    using (OracleAQQueue queue = new OracleAQQueue(this.NamePolicy.GetQueueName(address), conn, OracleAQMessageType.Xml))
                    {
                        queue.EnqueueOptions.Visibility = this.GetVisibilityMode(queueConnectionString);

                        using (var stream = new MemoryStream())
                        {
                            TransportMessageMapper.SerializeToXml(message, stream);
                            OracleAQMessage aqMessage = new OracleAQMessage(Encoding.UTF8.GetString(stream.ToArray()));
                            aqMessage.Correlation = message.CorrelationId;
                            try
                            {
                                queue.Enqueue(aqMessage);
                            }
                            catch (OracleException ex)
                            {
                                if (ex.Number == OraCodes.QueueDoesNotExist)
                                {
                                    throw new QueueNotFoundException {
                                              Queue = address
                                    };
                                }
                                else
                                {
                                    throw;
                                }
                            }
                        }
                    }
                }
            }
            catch (OracleException ex)
            {
                if (ex.Number == OraCodes.QueueDoesNotExist && address != null)
                {
                    throw new QueueNotFoundException {
                              Queue = address
                    };
                }
                else
                {
                    OracleAQMessageSender.ThrowFailedToSendException(address, ex);
                }
            }
            catch (Exception ex)
            {
                OracleAQMessageSender.ThrowFailedToSendException(address, ex);
            }
        }
Esempio n. 35
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 Action(object obj)
        {
            var cancellationToken = (CancellationToken)obj;

            while (!cancellationToken.IsCancellationRequested)
            {
                var result = new ReceiveResult();

                try
                {
                    using (var connection = new OracleConnection(this.ConnectionString))
                    {
                        using (var queue = new OracleAQQueue(this.workQueue, connection, OracleAQMessageType.Xml))
                        {
                            connection.Open();

                            this.SetupClientInfo(connection);

                            queue.Listen(null);

                            result = this.TryReceive(queue);
                        }
                    }
                }
                finally
                {
                    if (result.Message != null)
                    {
                        this.endProcessMessage(result.Message, result.Exception);
                    }
                }

                this.circuitBreaker.Success();
            }
        }