Beispiel #1
0
        private static void SimplePubMessage()
        {
            PubSubClient client = new PubSubClient(1);

            bool run = true;
            int messageId;
            messageId = 0;
            while (run)
            {
                Console.Write("say:");
                string messageToSend = Console.ReadLine();
                if (messageToSend.ToLower().Equals("exit"))
                    run = false;

                client.SendMessage(messageId, messageToSend);
            }
        }
Beispiel #2
0
        private static void OneClient10000ParalellMessages()
        {
            int countRequests = 0;
            int countReplies = 0;
            Stopwatch countTime = new Stopwatch();
            PubSubClient client = new PubSubClient(1);
            countTime.Start();

            var result = Parallel.For(0, 10000, i =>
            {
                Interlocked.Increment(ref countRequests);
                client.SendMessage(i, string.Format("Message number : {0}", i));
                Interlocked.Increment(ref countReplies);
            });

            while (!result.IsCompleted) ;

            countTime.Stop();

            Console.WriteLine("It took {0} ms to send 10000 messages", countTime.Elapsed.TotalSeconds);
        }