예제 #1
0
파일: Broker.cs 프로젝트: jangocheng/TaskMQ
        public bool PushMessage(TaskQueue.Providers.TaskMessage msg)
        {
            ChannelAnteroom ch = MessageChannels.GetAnteroomByMessage(msg.MType);
            if (ch == null)
            {
                logger.Warning("push: unknown message type: {0}", msg.MType);
                return false;
            }

            //ch.ChannelStatsIn.inc();
            //return true;

            msg.AddedTime = DateTime.UtcNow;
            bool status = ch.Push(msg);

            if (status)
            {
                ch.ChannelStatsIn.inc();
            }
            else
            {
                logger.Warning("push: can't enqueue message mtype: {0}, channel: {1}", msg.MType, ch.ChannelName);
            }
            // TODO: replace with suspend interface
            //var x = from t in Tasks
            //        where t.ChannelName == ch.ChannelName
            //        select t;
            //foreach (QueueTask t in x)
            //{
            //    t.Suspended = false;
            //}
            // ~

            return status;
        }
예제 #2
0
파일: Broker.cs 프로젝트: jangocheng/TaskMQ
        public TaskMessage Pop(string channel)
        {
            ChannelAnteroom ch = MessageChannels.GetAnteroom(channel);
            TaskQueue.Providers.TaskMessage item = ch.Next();

            if (item == null)
                return null;

            item.Processed = true;
            item.ProcessedTime = DateTime.UtcNow;
            ch.Update(item);

            return item;
        }
예제 #3
0
        private int ConsumerEntry(QueueTask task)
        {
            //Console.WriteLine("consumer: {0}", task.ChannelName);
            //QueueTask task = pi as QueueTask;
            IBrokerModule mod = task.Module;

            // Pop item from queue
            ChannelAnteroom ch = task.Anteroom;//MessageChannels.GetAnteroom(task.ChannelName);

            if (ch.InternalEmptyFlag)
            {
                return(1);
            }

            TaskQueue.Providers.TaskMessage message = ch.Next();

            if (message == null)
            {
                return(1);
            }
            //if (message == null)
            //{
            //    // this must be replaced with better way communication with message bus
            //    Console.WriteLine("Consumer empty, suspended: {0}", task.ChannelName);
            //    task.Suspended = true;
            //    return;
            //}
            TaskQueue.Providers.TaskMessage item = message;

            bool updated = ((IModConsumer)mod.MI).Push(task.Parameters, ref message);

            if (updated)
            {
                message.Processed     = true;
                message.ProcessedTime = DateTime.UtcNow;
            }

            updated = updated || (!Object.ReferenceEquals(item, message));// model is modified
            if (updated)
            {
                ch.Update(message);
            }
            ch.ChannelStatsOut.inc(); // inc stats
            return(0);
        }
예제 #4
0
        public void AddMessageChannel(MessageChannel mc)
        {
            lock (MChannelsList)
            {
                MessageChannels.Add(mc.UniqueName, MChannelsList.Count);
                //MessageChannelsModels.Add(mc.MessageType, MChannelsList.Count);
                MChannelsList.Add(mc);
            }
            ChannelAnteroom ante = GetAnteroom(mc.UniqueName);

            try
            {
                ante.Queue.OptimiseForSelector();
            }
            catch (Exception e)
            {
                logger.Exception(e, "OptimiseForSelector", "error in selector optimisation");
            }
        }
예제 #5
0
        public ChannelAnteroom GetAnteroom(string name)
        {
            ChannelAnteroom anteroom = null;

            if (Anterooms.TryGetValue(name, out anteroom))
            {
                return(anteroom);
            }
            else
            {
                MessageChannel mc = GetInstanceByName(name);
                anteroom             = new ChannelAnteroom();
                anteroom.ChannelName = name;

                TaskQueue.Providers.QueueConnectionParameters qparams = Connections[mc.ConnectionName];
                anteroom.Queue = qparams.QueueInstance;
                //anteroom.Queue = (TaskQueue.ITQueue)Activator.CreateInstance(qparams.QueueInstance.GetType()); //Queues.GetQueue(mc.QueueName);
                try
                {
                    anteroom.Queue.InitialiseFromModel(new RepresentedModel(typeof(TaskMessage)), qparams);// schema free only queue providers (mongodb)
                    // set selector to queue
                    anteroom.Queue.SetSelector(mc.consumerSelector);
                }
                catch (QueueConnectionException e)
                {
                    logger.Warning(e.Message);
                }
                catch (Exception e)
                {
                    logger.Exception(e, "Anterooms.Add", "anteroom initialisation error");
                }

                Anterooms.Add(name, anteroom);

                return(anteroom);
            }

            return(null);
        }
예제 #6
0
파일: Broker.cs 프로젝트: jangocheng/TaskMQ
 public long GetChannelOccupancy(string channelName)
 {
     ChannelAnteroom ch = MessageChannels.GetAnteroom(channelName);
     return ch.CountNow;
 }
예제 #7
0
파일: Broker.cs 프로젝트: jangocheng/TaskMQ
 // channels 
 public long GetChannelLevel(string messageType)
 {
     ChannelAnteroom ch = MessageChannels.GetAnteroomByMessage(messageType);
     return ch.Queue.GetQueueLength();
 }
예제 #8
0
        public ChannelAnteroom GetAnteroom(string name)
        {
            ChannelAnteroom anteroom = null;
            if (Anterooms.TryGetValue(name, out anteroom))
            {
                return anteroom;
            }
            else
            {
                MessageChannel mc = GetInstanceByName(name);
                anteroom = new ChannelAnteroom();
                anteroom.ChannelName = name;

                TaskQueue.Providers.QueueConnectionParameters qparams = Connections[mc.ConnectionName];
                anteroom.Queue = qparams.QueueInstance;
                //anteroom.Queue = (TaskQueue.ITQueue)Activator.CreateInstance(qparams.QueueInstance.GetType()); //Queues.GetQueue(mc.QueueName);
                try
                {
                    anteroom.Queue.InitialiseFromModel(new RepresentedModel(typeof(TaskMessage)), qparams);// schema free only queue providers (mongodb)
                    // set selector to queue
                    anteroom.Queue.SetSelector(mc.consumerSelector);
                }
                catch (QueueConnectionException e)
                {
                    logger.Warning(e.Message);
                }
                catch (Exception e)
                {
                    logger.Exception(e, "Anterooms.Add", "anteroom initialisation error");
                }

                Anterooms.Add(name, anteroom);

                return anteroom;
            }

            return null;
        }