예제 #1
0
파일: Program.cs 프로젝트: oisnull/hwl-api
        static void Test4()
        {
            foreach (var item in PushPositionQueue.QUEUE_SYMBOLS)
            {
                Console.WriteLine($"{item.Value} receive start...");
                MQConsumer.ReceiveMessage(item.Value, m =>
                {
                    string msg = Encoding.UTF8.GetString(m);
                    Console.WriteLine($"{item.Value}:{msg}");

                    try
                    {
                        PushModel model = JsonConvert.DeserializeObject <PushModel>(msg);
                        IConsumeHandler consumeHandler = ConsumeFactory.Create(model.PositionType);
                        consumeHandler.Process(model);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"Process failure:{CommonCs.GetExceptionMessages(ex)}");
                        Console.ResetColor();
                    }
                });
            }
        }
예제 #2
0
        private void Done(Task arg1, object c)
        {
            DateTime   tiden = DateTime.Now;
            MQConsumer cons  = c as MQConsumer;

            Console.WriteLine(cons.name + " Tiden = " + (tiden - start).TotalMilliseconds + " ms");
            Console.WriteLine(cons.name + " Tiden = " + (tiden - start).TotalSeconds + " s");
        }
예제 #3
0
 public MQCBD()
 {
     base.TrConstructor("%Z% %W% %I% %E% %U%");
     this.mqcbd                  = new MQBase.structMQCBD();
     this.mqcbd.strucId          = new byte[] { 0x43, 0x42, 0x44, 0x20 };
     this.mqcbd.version          = 1;
     this.mqcbd.callbackType     = 1;
     this.mqcbd.options          = 0;
     this.mqcbd.callbackArea     = IntPtr.Zero;
     this.mqcbd.callbackFunction = IntPtr.Zero;
     this.mqConsumer             = null;
     this.mqcbd.callbackName     = new byte[0x80];
     this.mqcbd.maxMsgLength     = -1;
     this.cbdId                  = NmqiTools.GetCurrentTimeInMs().ToString() + this.GetHashCode();
 }
예제 #4
0
        public void testConsumer()
        {
            for (int i = 0; i < consumers; i++)
            {
                MQConsumer c = new MQConsumer("Consumer nr. " + (i + 1) + "/" + consumers, antal);
                //pull messages
                Task.Run(() => c.ReceiveMessage()).ContinueWith(Done, c);
                //push messages
                //Task.Run(() => c.Start()).ContinueWith(Done,c);
            }

            start = DateTime.Now;
            MQPublisher p = new MQPublisher();

            p.SendMessage(antal);
        }
예제 #5
0
파일: Program.cs 프로젝트: oisnull/hwl-api
        static void Test2()
        {
            string testQueue = "test-1";

            //string msg = "Hello world";

            MQConsumer.ReceiveMessage(testQueue, m =>
            {
                Console.WriteLine(m);
            });

            while (true)
            {
                string inputText = Console.ReadLine();
                if (!string.IsNullOrEmpty(inputText) && !string.IsNullOrWhiteSpace(inputText))
                {
                    MQPublisher.PushMessage(testQueue, Encoding.UTF8.GetBytes(inputText));
                }
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: oisnull/hwl-api
        static void Test3()
        {
            foreach (var item in PushPositionQueue.QUEUE_SYMBOLS)
            {
                Console.WriteLine($"{item.Value} receive start...");
                MQConsumer.ReceiveMessage(item.Value, m =>
                {
                    string msg = Encoding.UTF8.GetString(m);
                    Console.WriteLine($"{item.Value}:{msg}");
                });
            }

            Func <string, PushModel> CreateModel = (txt) =>
            {
                return(new PushModel()
                {
                    //PositionType = PushPositionType.User,
                    PositionType = PushPositionType.Near,
                    PositionModel = new PushPositionModel()
                    {
                        UserId = 1,
                    },
                    SourceType = SourceType.TestCreate,
                    PushMessageType = 0,
                    MessageModel = new PushMessageModel()
                    {
                        Content = $"content-{txt}-test",
                    },
                });
            };

            while (true)
            {
                string inputText = Console.ReadLine();
                if (!string.IsNullOrEmpty(inputText) && !string.IsNullOrWhiteSpace(inputText))
                {
                    PushModel model = CreateModel(inputText);
                    PushEntry.Process(model);
                }
            }
        }
예제 #7
0
 /// <summary>
 /// 关闭连接
 /// </summary>
 public void Close()
 {
     MQConsumer?.Close();
     MQSession?.Close();
     MQCnnection?.Close();
 }