示例#1
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.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 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());
            }
        }
示例#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();
            }
        }
        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());
            }
        }
示例#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());
            }
        }
示例#7
0
        public void Publish(IMessage message)
        {
            var             oracleIntegrationModule = container.GetInstance <OracleAQIntegrationModule>();
            var             queue     = oracleIntegrationModule.GetOracleQueue(message.GetType().Name);
            OracleAQMessage aqMessage = new OracleAQMessage(SerializationHelper.SerializeObjectAsXml(typeof(OrderMessage), message));

            queue.Enqueue(aqMessage);
        }
示例#8
0
        private IMessage Consume(OracleAQQueue queue)
        {
            OracleAQMessage aqMessage = null;

            try
            {
                //Deserialize payload
                aqMessage = queue.Dequeue();
            }
            catch (OracleException ex)
            {
            }
            return(default(IMessage));
        }
        public static TransportMessage DeserializeFromXml(OracleAQMessage message)
        {
            if (message == null)
            {
                return(null);
            }

            XmlDocument bodyDoc;

            using (OracleXmlType type = (OracleXmlType)message.Payload)
            {
                bodyDoc = type.GetXmlDocument();
            }

            var bodySection = bodyDoc.DocumentElement.SelectSingleNode("Body").FirstChild as XmlCDataSection;

            var headerDictionary = new SerializableDictionary <string, string>();
            var headerSection    = bodyDoc.DocumentElement.SelectSingleNode("Headers");

            if (headerSection != null)
            {
                headerDictionary.SetXml(headerSection.InnerXml);
            }

            Address replyToAddress        = null;
            var     replyToAddressSection = bodyDoc.DocumentElement.SelectSingleNode("ReplyToAddress");

            if (replyToAddressSection != null && !string.IsNullOrWhiteSpace(replyToAddressSection.InnerText))
            {
                replyToAddress = Address.Parse(replyToAddressSection.InnerText.Trim());
            }

            MessageIntentEnum messageIntent = default(MessageIntentEnum);
            var messageIntentSection        = bodyDoc.DocumentElement.SelectSingleNode("MessageIntent");

            if (messageIntentSection != null)
            {
                messageIntent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), messageIntentSection.InnerText);
            }

            var transportMessage = new TransportMessage(new Guid(message.MessageId).ToString(), headerDictionary)
            {
                Body = bodySection != null?Encoding.UTF8.GetBytes(bodySection.Data) : new byte[0],
                           ReplyToAddress = replyToAddress,
                           MessageIntent  = messageIntent,
            };

            return(transportMessage);
        }
        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());
            }
        }
        public static TransportMessage DeserializeFromXml(OracleAQMessage message)
        {
            if (message == null)
            {
                return null;
            }

            XmlDocument bodyDoc;
            using (OracleXmlType type = (OracleXmlType)message.Payload)
            {
                bodyDoc = type.GetXmlDocument();
            }

            var bodySection = bodyDoc.DocumentElement.SelectSingleNode("Body").FirstChild as XmlCDataSection;

            var headerDictionary = new SerializableDictionary<string, string>();
            var headerSection = bodyDoc.DocumentElement.SelectSingleNode("Headers");
            if (headerSection != null)
            {
                headerDictionary.SetXml(headerSection.InnerXml);
            }

            Address replyToAddress = null;
            var replyToAddressSection = bodyDoc.DocumentElement.SelectSingleNode("ReplyToAddress");
            if (replyToAddressSection != null && !string.IsNullOrWhiteSpace(replyToAddressSection.InnerText))
            {
                replyToAddress = Address.Parse(replyToAddressSection.InnerText.Trim());
            }

            MessageIntentEnum messageIntent = default(MessageIntentEnum);
            var messageIntentSection = bodyDoc.DocumentElement.SelectSingleNode("MessageIntent");
            if (messageIntentSection != null)
            {
                messageIntent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), messageIntentSection.InnerText);
            }

            var transportMessage = new TransportMessage(new Guid(message.MessageId).ToString(), headerDictionary)
            {
                Body = bodySection != null ? Encoding.UTF8.GetBytes(bodySection.Data) : new byte[0],
                ReplyToAddress = replyToAddress,
                MessageIntent = messageIntent,
            };

            return transportMessage;
        }
示例#12
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));
        }
        /// <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);
                }
            }
        }
示例#14
0
        //TODO: think about moving this just before transaction commit so Oracle can be switched to in memory queue
        //TODO: which doesn't need to be persisted. invalid notify should only result in more processing
        public void Notify(OracleNotifyInfoConverter[] notifiers, string target)
        {
            if (notifiers == null || notifiers.Length == 0)
            {
                return;
            }
            var msgs   = new OracleAQMessage[notifiers.Length];
            var sender = new OracleAQAgent(target);

            for (int i = 0; i < msgs.Length; i++)
            {
                msgs[i] = new OracleAQMessage(notifiers[i])
                {
                    SenderId = sender, Recipients = Recipients
                }
            }
            ;
            Queue.Value.EnqueueArray(msgs);
        }
        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());
            }
        }
示例#16
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());
            }
        }
示例#18
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());
            }
        }
示例#19
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();
            }
        }
示例#20
0
 //TODO: think about moving this just before transaction commit so Oracle can be switched to in memory queue
 //TODO: which doesn't need to be persisted. invalid notify should only result in more processing
 public void Notify(OracleNotifyInfoConverter[] notifiers, string target)
 {
     if (notifiers == null || notifiers.Length == 0)
         return;
     var msgs = new OracleAQMessage[notifiers.Length];
     var sender = new OracleAQAgent(target);
     for (int i = 0; i < msgs.Length; i++)
         msgs[i] = new OracleAQMessage(notifiers[i]) { SenderId = sender, Recipients = Recipients };
     Queue.Value.EnqueueArray(msgs);
 }
 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);
         });
     }
 }
        /// <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);
            }
        }
        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);
                }
            });
        }
        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);
                }
            });
        }