Example #1
0
        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;
        }
Example #2
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);
        }