Beispiel #1
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();
            }
        }
Beispiel #2
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 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 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();
            }
        }