Ejemplo n.º 1
0
 public ConsumeOrderlyStatus consumeMessage(List list, ConsumeOrderlyContext context)
 {
     context.setAutoCommit(false);
     for (int i = 0; i < list.size(); i++)
     {
         var    msg  = list.get(i) as Message;
         byte[] body = msg.getBody();
         var    str  = Encoding.Default.GetString(body);
         Console.WriteLine(str);
     }
     this.consumeTimes.incrementAndGet();
     if ((this.consumeTimes.get() % 2) == 0)
     {
         return(ConsumeOrderlyStatus.SUCCESS);
     }
     else if ((this.consumeTimes.get() % 3) == 0)
     {
         return(ConsumeOrderlyStatus.ROLLBACK);
     }
     else if ((this.consumeTimes.get() % 4) == 0)
     {
         return(ConsumeOrderlyStatus.COMMIT);
     }
     else if ((this.consumeTimes.get() % 5) == 0)
     {
         context.setSuspendCurrentQueueTimeMillis(3000);
         return(ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT);
     }
     return(ConsumeOrderlyStatus.SUCCESS);
 }
Ejemplo n.º 2
0
        public ConsumeOrderlyStatus consumeMessage(List list, ConsumeOrderlyContext context)
        {
            //throw new NotImplementedException();

            context.setAutoCommit(false);
            Console.WriteLine(Thread.currentThread().getName() + " Receive new messages :: " + list + " \n");
            this.consumeTimes.incrementAndGet();
            if ((this.consumeTimes.get() % 2) == 0)
            {
                return(ConsumeOrderlyStatus.SUCCESS);
            }
            else if ((this.consumeTimes.get() % 3) == 0)
            {
                return(ConsumeOrderlyStatus.ROLLBACK);
            }
            else if ((this.consumeTimes.get() % 4) == 0)
            {
                return(ConsumeOrderlyStatus.COMMIT);
            }
            else if ((this.consumeTimes.get() % 5) == 0)
            {
                context.setSuspendCurrentQueueTimeMillis(3000);
                return(ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT);
            }
            return(ConsumeOrderlyStatus.SUCCESS);
        }
 public ConsumeOrderlyStatus consumeMessage(List msgs, ConsumeOrderlyContext context)
 {
     try
     {
         var messageList = msgs.iterator();
         while (messageList.hasNext())
         {
             MessageExt msg     = (MessageExt)messageList.next();
             byte[]     msgbody = msg.getBody();
             string     body    = Encoding.UTF8.GetString(msgbody);
             Console.WriteLine("===> consumed msg :" + body);
         }
     }
     catch (Exception ex)
     {
     }
     return(ConsumeOrderlyStatus.SUCCESS);
 }