コード例 #1
0
ファイル: Program.cs プロジェクト: futuristsolutions/Research
        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();
            }
        }
コード例 #2
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.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());
            }
        }
コード例 #3
0
        /// <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);
                }
            }
        }
コード例 #4
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());
            }
        }
コード例 #5
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());
            }
        }
コード例 #6
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());
            }
        }
コード例 #7
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();
            }
        }
コード例 #8
0
        /// <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);
            }
        }
コード例 #9
0
        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);
                }
            });
        }
コード例 #10
0
        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);
                }
            });
        }
コード例 #11
0
 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);
         });
     }
 }