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 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 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());
            }
        }
Esempio n. 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());
            }
        }
        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. 6
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());
            }
        }
        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());
            }
        }
        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. 9
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();
                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());
            }
        }
        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());
            }
        }
Esempio n. 12
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());
            }
        }
Esempio n. 13
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();
            }
        }