Example #1
0
        public MessageState AddQueue(QProperties prop, out MQueue mq)
        {
            if (MQ.ContainsKey(prop.QueueName))
            {
                if (prop.ReloadOnStart)
                {
                    MQueue q = new MQueue(prop);
                    MQ[prop.QueueName] = q;
                    mq = q;
                }
                else
                {
                    mq = MQ[prop.QueueName];
                }
                return(MessageState.AllreadyExists);
            }
            //if (prop.IsDbQueue)
            //{
            //    AddDbQueue(prop.QueueName, prop.IsTrans);
            //}
            MQueue queue = new MQueue(prop);

            MQ[prop.QueueName] = queue;
            mq = queue;
            Netlog.InfoFormat("AddQueue : {0}", prop.Print());
            return(MessageState.Ok);
        }
Example #2
0
        /// <summary>Deletes a queue on a Message Queuing server.</summary>
        /// <param name="queueName">The location of the queue to be deleted. </param>
        public bool RemoveQueue(string queueName)
        {
            if (queueName == null)
            {
                throw new ArgumentNullException("queueName");
            }
            if (queueName.Length == 0)
            {
                throw new ArgumentException("InvalidParameter", "queueName");
            }
            //RemoveDbQueue(queueName);

            MQueue queue;

            if (MQ.TryRemove(queueName, out queue))
            {
                Netlog.InfoFormat("RemoveQueue : {0}", queueName);
                return(true);
            }
            else
            {
                Netlog.InfoFormat("RemoveQueue not removed : {0}", queueName);
                return(false);
            }
        }
Example #3
0
        protected override void OnMessageReceived(QueueItemEventArgs e)
        {
            base.OnMessageReceived(e);
            IQueueItem item = e.Item;

            if (item == null)
            {
                return;
            }

            if (e.State == ItemState.Dequeue)
            {
                base.CommitTrans(item.ItemId, item.HasAttach);
            }
            Console.WriteLine("Queue{0} Items count: {1}", QueueName, base.Count);
            if (item != null)
            {
                Console.WriteLine("Queue{0} MessageReceived: {1}, Duration:{2}", QueueName, item.ItemId, item.Duration());
            }
            else
            {
                Console.WriteLine("Queue{0} Receive timeout", QueueName);
            }

            Netlog.InfoFormat("OnMessageReceived:{0} Received:{1}", e.Item.MessageId, e.Item.SentTime);

            if (base.Count <= 0)
            {
                TimeSpan ts = DateTime.Now.Subtract(start);
                Console.WriteLine("Time took:{0}", ts.TotalSeconds);
            }
        }
Example #4
0
        private void ReEnqueueFiles()
        {
            if (reEnqueueItems)
            {
                return;
            }
            try
            {
                Console.WriteLine("Start ReEnqueueQueueItems");

                reEnqueueItems = true;

                string path = GetRelayPath();

                if (Directory.Exists(path))
                {
                    string[] messages = Directory.GetFiles(path, "*.mcq");
                    if (messages == null || messages.Length == 0)
                    {
                        return;
                    }

                    Console.WriteLine("{0} items found to ReEnqueue", messages.Length);

                    Netlog.InfoFormat("ReEnqueueFiles: {0} ", messages.Length);


                    foreach (string message in messages)
                    {
                        //while (this.Count > 1000)
                        //{

                        //    Thread.Sleep(1000);
                        //}

                        QueueItem item = QueueItem.ReadFile(message);
                        if (item != null)
                        {
                            Enqueue(item as IQueueItem);
                        }
                        SysUtil.DeleteFile(message);
                        Thread.Sleep(100);
                    }
                    Netlog.Info("ReEnqueueFiles finished. ");
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
            finally
            {
                reEnqueueItems = false;
            }
        }
Example #5
0
        private static void OnMessageReceived(IQueueItem item)
        {
            if (item == null)
            {
                return;
            }
            Console.WriteLine("Queue{0} Items count: {1}", queue.QueueName, queue.Count);
            if (item != null)
            {
                Console.WriteLine("Queue{0} ReceiveCompleted: {1}", queue.QueueName, item.ItemId);
            }
            else
            {
                Console.WriteLine("Queue{0} Receive timeout", queue.QueueName);
            }

            Netlog.InfoFormat("OnMessageReceived:{0} Received:{1}", item.MessageId, item.SentTime);
        }
Example #6
0
        private void Init()
        {
            if (Initilize)
            {
                return;
            }
            numThreads = MaxServerConnections;
            servers    = new Thread[numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                //if (IsAsync)
                //    servers[i] = new Thread(RunAsync);
                //else
                //    servers[i] = new Thread(Run);

                servers[i] = new Thread(Run);
                servers[i].IsBackground = true;
                servers[i].Start();
            }
            OnLoad();

            Netlog.InfoFormat("Waiting for client connection {0}...\n", PipeName);
        }
Example #7
0
 protected override void OnMessageArraived(QueueItemEventArgs e)
 {
     base.OnMessageArraived(e);
     Netlog.InfoFormat("OnMessageArraived:{0} Arrived:{1}", e.Item.MessageId, e.Item.ArrivedTime);
 }
Example #8
0
 protected override void OnErrorOcurred(ErrorOcurredEventArgs e)
 {
     base.OnErrorOcurred(e);
     Netlog.InfoFormat("OnErrorOcurred:{0} ", e.Message);
 }
Example #9
0
 public Channel(McChannelProperties prop)
     : base(prop)
 {
     Netlog.InfoFormat("Start Queue{0} ...", QueueName);
 }