Ejemplo n.º 1
0
        IQueueAck ExecRout(QueueItem item, QueueHost qh)
        {
            if (qh == null)
            {
                throw new MessageException(MessageState.InvalidMessageHost, "Invalid QueueHost for Routing " + item.Host);
            }
            IQueueAck ack = null;

            if (qh.IsLocal)
            {
                item.Host = qh.HostName;
                MQueue Q = Get(item.Host);
                if (Q == null)
                {
                    throw new MessageException(MessageState.InvalidMessageHost, "message.RoutHostName not found " + item.Host);
                }
                ack = Q.Enqueue(item);
                return(ack);// ptr.MessageState;
            }

            var api = new QueueApi(qh.NetProtocol);

            ack = api.SendAsync(item, 0);
            return(ack);
        }
Ejemplo n.º 2
0
        public static void SendItemAsync(QueueApi q, QueueItem item, int connectTimeOut, Action <IQueueAck> action)
        {
            q.SendAsync(item, connectTimeOut, action);

            //DateTime start = DateTime.Now;
            //q.SendAsync(item, connectTimeOut, (ack) =>
            //{
            //    //Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}, item:{6}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier, ack.Duration, item);
            //});
        }
Ejemplo n.º 3
0
        static void SendItem(QueueApi q, long item)
        {
            DateTime  start = DateTime.Now;
            QueueItem msg   = new QueueItem();

            msg.SetBody("Hello world " + DateTime.Now.ToString("s"));
            if (q.IsAsync)
            {
                q.SendAsync(msg, 50000000, (ack) =>
                {
                    Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}, item:{6}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier, ack.Duration, item);
                });
            }
            else
            {
                var ack = q.Enqueue(msg, 50000000);
                Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}, item:{6}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier, ack.Duration, item);
            }
            //var duration = DateTime.Now.Subtract(start);
            //var milliseconds = duration.TotalMilliseconds;
            //Console.WriteLine("duration: {0}, item: {1}", milliseconds, item);
        }
Ejemplo n.º 4
0
        static void SendMulti(QueueApi q, int maxItems)
        {
            long     counter  = 0;
            int      interval = 1;
            DateTime start    = DateTime.Now;

            for (int i = 0; i < maxItems; i++)
            {
                //Task.Factory.StartNew(() => SendItem(q, i));

                QueueItem msg = new QueueItem();
                msg.Label = i.ToString();
                msg.SetBody("Hello world " + DateTime.Now.ToString("s"));

                Task.Factory.StartNew(() =>
                {
                    if (q.IsAsync)
                    {
                        q.SendAsync(msg, 50000000, (ack) =>
                        {
                            Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier, ack.Duration);
                            Interlocked.Increment(ref counter);
                        });
                    }
                    else
                    {
                        var ack = q.Enqueue(msg, 50000000);
                        Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier, ack.Duration);
                        Interlocked.Increment(ref counter);
                    }
                });
                //Thread.Sleep(interval);
            }

            while (Interlocked.Read(ref counter) < (maxItems))
            {
                Thread.Sleep(interval);
            }


            //while (true)
            //{
            //    if (counter > maxItems)
            //        break;
            //    Interlocked.Increment(ref counter);

            //    Task.Factory.StartNew(() => SendItem(q, Interlocked.Read(ref counter)));

            //    //SendItem(q,counter);

            //    //QueueItem msg = new QueueItem();
            //    //msg.SetBodyText("Hello world " + DateTime.Now.ToString("s"));
            //    //q.SendAsync(msg, 5000, (ack) =>
            //    //{
            //    //    Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier);
            //    //});

            //    //Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}", ack.MessageState,ack.Creation,ack.Host,ack.Label, ack.Identifier);

            //    //counter++;
            //    Thread.Sleep(interval);
            //}

            var duration     = DateTime.Now.Subtract(start);
            var milliseconds = duration.TotalMilliseconds;

            Console.WriteLine("duration: {0}, count: {1}, itemDuration: {2}", milliseconds - (interval * counter), counter, (milliseconds - (interval * counter)) / counter);
        }
Ejemplo n.º 5
0
 public static IQueueAck SendItemAsync(QueueApi q, QueueItem item, int connectTimeOut)
 {
     return(q.SendAsync(item, connectTimeOut));
 }